24

I have a react-native@0.26.2 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?

Scimonster
  • 32,893
  • 9
  • 77
  • 89
SaroVin
  • 1,583
  • 3
  • 23
  • 46
  • I get same error when running Jest. Trying to get Jest working, see here: http://stackoverflow.com/questions/37474160/cannot-get-jest-react-native-working `ReferenceError: __DEV__ is not defined` – Giant Elk May 28 '16 at 02:37
  • 2
    Possible duplicate of [ReferenceError: Can't find variable: \_\_DEV\_\_](http://stackoverflow.com/questions/33281733/referenceerror-cant-find-variable-dev) – Max MacLeod Jun 24 '16 at 10:43

7 Answers7

25

Adding

/* global __DEV__ */

To the top of the file worked for me.

FishStix
  • 4,994
  • 9
  • 38
  • 53
11

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

Removing .babelrc seems to fix the problem.

My .babelrc:

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

Clintm
  • 4,505
  • 3
  • 41
  • 54
  • Then I end up with this problem: https://stackoverflow.com/questions/53326986/trace-the-node-type-spreadproperty-has-been-renamed-to-spreadelement-at-object – sudo Jul 17 '19 at 07:21
5

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.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
rrcobb
  • 84
  • 1
  • 5
3

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

Muzamil ijaz
  • 163
  • 10
2

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.

JiajiaGu
  • 1,279
  • 14
  • 10
1

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

Nima Soroush
  • 12,242
  • 4
  • 52
  • 53
-3

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

ChenYuan
  • 33
  • 3