升级到React Native 0.59.5后,我得到:
Uncaught reference error: require is not defined
babel.config.js
module.exports = {
presets: [
'module:metro-react-native-babel-preset',
'@babel/preset-flow',
[
'@babel/preset-env',
{
targets: {
esmodules: true,
},
},
],
'airbnb',
],
plugins: [
'transform-class-properties',
['@babel/plugin-proposal-decorators', { legacy: true }]
],
};
节点:8.10.0 npm :5.6.0 反应原生:0.59.5
答案 0 :(得分:0)
尝试执行以下babel配置,如果丢失,不要忘记安装所需的库:
module.exports = {
presets: ["@babel/preset-flow", "module:metro-react-native-babel-preset"],
plugins: [
["@babel/plugin-proposal-decorators", { legacy: true }],
["@babel/plugin-transform-flow-strip-types"],
["babel-plugin-react-native-nodeify-hack"],
"@babel/plugin-syntax-dynamic-import",
[
"@babel/plugin-proposal-class-properties",
{
loose: true
}
],
"@babel/plugin-transform-regenerator",
[
"@babel/plugin-transform-runtime",
{
helpers: false,
regenerator: true
}
]
]
};
然后您可以使用此命令清理项目(仅适用于IOS)
watchman watch-del-all && rm -rf node_modules && npm install && rm -rf $TMPDIR/haste-map-react-native-packager-* && rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf ~/Library/Developer/Xcode/DerivedData && pod deintegrate ios/{YOUR_PROJECT}.xcodeproj && rm -rf ./ios/Pods && pod install --project-directory=./ios/ && rm -f /ios/build && npm cache verify
然后重新运行项目
react-native run-ios
希望这能解决您的问题