我有一个 react-native@0.26.2 项目。我已经删除了 node_modules 文件夹,并在我给出了以下命令之后:
npm i
react-native upgrade
但我收到此错误:
react-native.js:15
ReferenceError: __DEV__ is not defined
我该如何解决?
我有一个 react-native@0.26.2 项目。我已经删除了 node_modules 文件夹,并在我给出了以下命令之后:
npm i
react-native upgrade
但我收到此错误:
react-native.js:15
ReferenceError: __DEV__ is not defined
我该如何解决?
添加
/* global __DEV__ */
到文件的顶部为我工作。
也许这个?https://github.com/facebook/react-native/issues/7814
删除 .babelrc 似乎可以解决问题。
我的 .babelrc:
{“预设”:[“react-native”]}
由于这是第一个搜索结果,我想为那些在 react-native-web 和 Jest 中遇到此问题的人提供另一个提示。
如https://github.com/facebookincubator/create-react-app/issues/1085 中所述,如果您要映射'react-native'
到'react-native-web'
构建系统(对我而言是 webpack),那么您还需要在 Jest 配置中映射。
我看到的是
ReferenceError: __DEV__ is not defined
当我通过 Jest 进行测试时。添加
moduleNameMapper: {
'^react-native$': 'react-native-web',
}
以jest.config.js
固定这对我来说。
向 devDependencies 添加 'babel-preset-react-native' 解决了这个问题
已经想出解决方案适用于整个项目,只需将globals
属性添加到 .eslintrc.json 文件:
{
"rules":{
//your rules
},
"globals": {
"__DEV__": true
}
}
请注意,globals
和rules
应该在同一个 json 对象中。