React Native - __DEV__ is not defined

24,251

Solution 1

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

Removing .babelrc seems to fix the problem.

My .babelrc:

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

Solution 2

Adding

/* global __DEV__ */

To the top of the file worked for me.

Solution 3

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.

Solution 4

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

Share:
24,251
SaroVin
Author by

SaroVin

Updated on October 29, 2021

Comments

  • SaroVin
    SaroVin over 2 years

    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?