Reputation: 876
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?
<head>
<title>Testing 123</title>
</head>
<body>
<div id="root"></div>
</body>
import React from 'react';
import ReactDOM from 'react-dom';
Meteor.startup(() => {
ReactDOM.render(<h1>Hello World</h1>, document.getElementById('root'));
});
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!
Upvotes: 3
Views: 1223
Reputation: 1548
It seems your main.js is in Client with a capital C. Try renaming Client
folder to client
.
This would cause your code to be run server side where document is not defined.
Upvotes: 3
Reputation: 2870
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...
Upvotes: 4