Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor crashing "ReferenceError: document is not defined"

I'm trying to do a simple hello world in Meteor using React.js. When i try running the application it's crashing with "ReferenceError: document is not defined". This error doesn't make sense to me, how can document be undefined?

client HTML

<head>
  <title>Testing 123</title>
</head>

<body>
  <div id="root"></div>
</body>

Client Javascript

    import React from 'react';
    import ReactDOM from 'react-dom';

    Meteor.startup(() => {
        ReactDOM.render(<h1>Hello World</h1>, document.getElementById('root'));
    });

Full error log

C:\Users\Klynicol\AppData\Local\.meteor\packages\meteor-tool\1.4.4_3\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:280
                    throw(ex);
                    ^

ReferenceError: document is not defined
at Client/main.js:18:28
at Function.time (c:\MeteorTut\meteortut\.meteor\local\build\programs\server\profile.js:309:28)
at c:\MeteorTut\meteortut\.meteor\local\build\programs\server\boot.js:312:13
at c:\MeteorTut\meteortut\.meteor\local\build\programs\server\boot.js:353:5
at Function.run (c:\MeteorTut\meteortut\.meteor\local\build\programs\server\profile.js:510:12)
at c:\MeteorTut\meteortut\.meteor\local\build\programs\server\boot.js:351:11
Exited with code: 1
Your application is crashing. Waiting for file change.

Any help would be greatly appreciated!

like image 522
Rager Avatar asked Jan 18 '26 18:01

Rager


1 Answers

I have a feeling that this is happening because your code is trying to run in the server alongside the client. And since there is no document on the server, it's throwing an error.

This could be because of the client directory that you have. It's named as Client instead of client. I'm not entirely sure if the directory structures are case sensitive, but rename Client to client and have a go at it.

Ah! looks like @Damien Monni beat me to it...

like image 63
blueren Avatar answered Jan 21 '26 08:01

blueren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!