SaroVin
SaroVin

Reputation: 1773

React Native - __DEV__ is not defined

I have a [email protected] project. I have deleted the node_modules folder and after i have given the following commands:

npm i
react-native upgrade

but I get this error:

react-native.js:15 

ReferenceError: __DEV__ is not defined

How do I fix?

Upvotes: 28

Views: 35774

Answers (7)

M Muzzammil ijaz
M Muzzammil ijaz

Reputation: 178

If you are using jest.config.js file, then place this in that

globals: {
    __DEV__: true
},

It will work then. Happy :)

enter image description here

Upvotes: 5

JiajiaGu
JiajiaGu

Reputation: 1339

Have figured out the solution works on the entire project,just add globals property to the .eslintrc.json file:

{
    "rules":{
        //your rules
    },
    "globals": {
        "__DEV__": true
    }
}

Note that globals and rules should be in the same json object.

Upvotes: 5

rrcobb
rrcobb

Reputation: 84

Since this is the first search result, I wanted to drop another hint for those who are running into this issue with react-native-web and Jest.

As detailed in https://github.com/facebookincubator/create-react-app/issues/1085, if you are mapping 'react-native' to 'react-native-web' in your build system (webpack, for me), then you also need that mapping in your Jest config.

I was seeing the

ReferenceError: __DEV__ is not defined

when I ran tests through Jest. Adding

moduleNameMapper: {
    '^react-native$': 'react-native-web',
}

to jest.config.js fixed this for me.

Upvotes: 5

FishStix
FishStix

Reputation: 5124

Adding

/* global __DEV__ */

To the top of the file worked for me.

Upvotes: 27

Nima Soroush
Nima Soroush

Reputation: 12814

Adding 'babel-preset-react-native' to devDependencies solved this issue

Upvotes: 1

ChenYuan
ChenYuan

Reputation: 1

The .babelrc file is hidden in folder .
I just delete it and then my react native project work.

Upvotes: -3

Clintm
Clintm

Reputation: 4877

Maybe this? https://github.com/facebook/react-native/issues/7814

Removing .babelrc seems to fix the problem.

My .babelrc:

{ "presets": ["react-native"] }

Upvotes: 11

Related Questions