-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[0.56.0][iOS][Android] Can't find variable: require #21048
Comments
I've the same error with react-native@^0.57.0-rc.4 and babel@^7.0.0 |
From extensive digging, I think it has something to do with my babel configuration, which I spent a lot of time messing with to try and get the bundle to compile, and my tests (written with Jest) to also run (and compile the react-native-based dependencies). Still working through finding a solution. |
good luck, me too, spent 10 hours on it from now, |
found that was caused by corejs option
package.json
and I added in my app's code hope this helps |
It looks like you are using an older version of React Native. Please update to the latest release, v0.57 and verify if the issue still exists. The ":rewind:Old Version" label will be removed automatically once you edit your original post with the results of running |
@TakioN I tried your suggestion but it didn't work for me... Using react-native Edit: here is my module.exports = {
"retainLines": true,
"compact": true,
"comments": false,
"presets": [
"@babel/env",
"@babel/react",
"module:metro-react-native-babel-preset"
],
"plugins": [
"syntax-async-functions",
"@babel/syntax-class-properties",
["@babel/proposal-decorators", { "legacy": true }],
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"@babel/transform-runtime"
],
"sourceMaps": false,
"exclude": ["**/*.png", "**/*.jpg", "**/*.gif"]
}; and my
|
@m-vdb try to remove |
thanks a lot @TakioN 🙏all your recommendations together fixed it! (then I stumbled upon an other error, #20588, and I managed to fixed that too, I think). key takeaway: cleanup babel config and rely on |
Wow, this error is frustrating. I've tried all of the above to no avail. And there's very little information to go on. I figured it might be because of either the fact that I use typescript and/or storybook, but the only way to find out is removing EVERYTHING and the re-add one dependency at a time. A maneuver that's extremely painful when you have a production ready app. |
I even hit this error when I init a completely new project with react-native init NOTES:
Steps to reproduce:
My react-native info:
Well I might as well give up on the migration if it doesn't even work for a completely new project 😭 |
Nothing worked for me until I did reset the transform cache:
Now it works with package.json
and babel.config.js
Looks like root cause was transform caching failure..? |
OMG. It worked for me as well. I spent 5 hours straight into this error, and I was trying many different .babelrc setups and none of them worked only because the packager cached the very first wrong one... |
Thank you! Finally my app loads again after many many wasted hours! 🎉
That's what seemed to do it for me. Plus I also originally had this in my .babelrc file:
The Typescript resource that RN linked to in RN 0.56 said to add those @babel presets/plugins...but in the end, but I guess that's only valid for React web, not RN, so I now just have this and it's working (but only after I ran that rest of the transform cache command above):
|
So, it seems to me that the solution is simply to reset the cache of the bundler, and is not an actual bug of the Can this be closed then? |
had this error and fixed it by removing |
I don't think the error was due to a stale bundler cache (see here). I eventually fixed mine by changing babel config, so I guess my issue is solved. I don't know/think the wider issue is resolved, but I no longer have a horse in this race. Close if you like. Edit: In fact, I think the issue you referenced (#21475) shows that it's happening in fresh projects. Is the thinking that it's happening because they already had a bundler cache? |
Ok it seems that it's babel config related, so mostly a single project issue or Metro one. Atm when installing a new project it should be created with Metro 0.48+ which should fix these issues. We'll also do a new 0.57.3 soon to make sure that also "upgrading" uses it. |
this worked for me too |
For those whose cache clearing didn't work. Try deleting .bablerc file. It has its own ways of effecting cache. Mine issues was only resolved after i deleted this. Platforms:
|
I ran into this issue today. For me, it was the |
Environment
`react-native info` output
Description
babel
is pointing to7.0.0-beta.47
by usingyarn
resolutionsWhen building for development or release, I get a
can't find variable: require
error. This happens on both iOS and Android, and seems to be in code that I have no control over. Here is the output on iOS:Android doesn't make it far enough to get a Redbox - it throws before it gets to that point, but I same the same error thrown using
logcat
. The error on Android iscom.facebook.react.devsupport.JSException: Can't find variable: require
.I have seen #19827 (and its various children), but all of them seem to imply that only production is broken, not development. And none of the errors included have anything to do with
require
.Based on comments in other threads: I am not using generators. I am using
async
/await
.I have tried removing
node_modules
, clearing the watchman cache, clearing the yarn cache, clearing the build folder in XCode, clearing the Android build artifacts.At first I thought that this issue was due to Mojave, but the builds produced by my CI platform are also broken, and they are running in Xcode 9.4.1 and macOS Sierra/High Sierra, or Linux for Android builds.
Reproducible Demo
I have no idea how to reproduce this at this stage. Still investigating.
The text was updated successfully, but these errors were encountered: