After upgrading to React Native 0.59.5, I am getting:
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 }]
],
};
Node : 8.10.0 npm : 5.6.0 React native : 0.59.5
Try to do the following babel config and don't forget to install the required libraries if missing:
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
}
]
]
};
Then you can clean the project with this command (IOS Only)
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
And then re-run the project
react-native run-ios
Hopefully this will resolve your issue
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.