Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: __DEV__ is not defined #7426

Closed
ericat opened this issue May 6, 2016 · 4 comments
Closed

ReferenceError: __DEV__ is not defined #7426

ericat opened this issue May 6, 2016 · 4 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@ericat
Copy link

ericat commented May 6, 2016

As an experiment, I am trying to make isomorphic-relay work in react-native, but I stumble onto the error below as soon as I try to import a component into renderOnServer.js.

This has been mentioned before here, but I am not sure how to fix it.

/node_modules/react-native/Libraries/react-native/react-native.js:15
if (__DEV__) {
    ^

ReferenceError: __DEV__ is not defined

This crashes the entire graphql server.

I am on a Mac, versions:
react-native@0.25.1
react-relay @0.8.1
isomorphic-relay@0.7.0-beta.0

My renderOnServer.js now is minimal:

import IsomorphicRelay from 'isomorphic-relay';
import path from 'path';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import Relay from 'react-relay';
import AppHomeRoute from './routes/AppHomeRoute';
import MyComponent from './components/MyComponent'; // offending line

export default (res, next) => {
  return next();
};

in server.js:

[...]
app.get('/', (req, res, next) => {
  renderOnServer(res, next);
});
[...]

Full stack trace:

/Users/ericat/nativeRelay/node_modules/react-native/Libraries/react-native/react-native.js:15
if (__DEV__) {
    ^

ReferenceError: __DEV__ is not defined
    at Object.<anonymous> (/Users/ericat/nativeRelay/node_modules/react-native/Libraries/react-native/react-native.js:15:5)
    at Module._compile (module.js:425:26)
    at Module._extensions..js (module.js:432:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/ericat/nativeRelay/node_modules/babel-register/lib/node.js:166:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (MyComponent.js:2:1)
    at Module._compile (module.js:425:26)

What am I doing wrong? It looks like a bug. If I set var __DEV__ = true; at the beginning of the file, the next error would be:

Error: Cannot find module 'ReactNative'
[...]
    at Object.<anonymous> (/Users/ericat/nativeRelay/node_modules/react-native/Libraries/react-native/react-native.js:181:27)
@vning93
Copy link

vning93 commented May 7, 2016

+1

@satya164
Copy link
Contributor

satya164 commented May 7, 2016

You can't import React Native on server of course. When you import a component which imports React Native, you'll get this error. You can make 2 components, MyComponent.js and MyComponent.native.js for browser and native respectively.

@satya164
Copy link
Contributor

satya164 commented May 7, 2016

@facebook-github-bot answered

@ghost
Copy link

ghost commented May 7, 2016

Closing this issue as @satya164 says the question asked has been answered. Please help us by asking questions on StackOverflow. StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only.

@ghost ghost closed this as completed May 7, 2016
@ghost ghost added the Ran Commands One of our bots successfully processed a command. label May 7, 2016
@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants