react-native: Cannot read property 'tokens' of undefined
Description
I’m testing my app on react-native
master. And having such error during transformation
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 548): SyntaxError: TransformError: /Users/headless/tmp/TestIntlCrash/node_modules/intl/lib/core.js: Cannot read property 'tokens' of undefined
Reproduction
new project with intl dependency https://github.com/skv-headless/TestIntlCrash
Solution
Not yet.
Additional Information
- React Native version: [master], works on 0.40
- Platform: [iOS, Android]
- Operating System: [MacOS]
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 23 (10 by maintainers)
Commits related to this issue
- Properly handle babel ignored files, returning only the contents Fixes #12071, #13168 — committed to kevinold/react-native by deleted user 7 years ago
- Properly handle babel ignored files, returning only the contents Summary: - [x] Explain the **motivation** for making this change. - [x] Provide a **test plan** demonstrating that the code is solid. ... — committed to facebook/react-native by deleted user 7 years ago
- Properly handle babel ignored files, returning only the contents Summary: - [x] Explain the **motivation** for making this change. - [x] Provide a **test plan** demonstrating that the code is solid. ... — committed to makadaw/react-native by deleted user 7 years ago
@ericvicenti please reopen the issue
@gitim I am getting this again in 0.42-rc2. It does work on 0.41.
Or as @didaKtik wrote, just add
"postinstall": "rm -f node_modules/intl/.babelrc"
to yourpackage.json
as proposed in https://github.com/andyearnshaw/Intl.js/pull/264I have the same issue, I debugged it a little bit and I found that error occurs on the line https://github.com/babel/babel/blob/master/packages/babel-generator/src/index.js#L16, because somehow
ast
for this file is undefined.Looks like it was fixed in 0.45.1
https://github.com/facebook/react-native/commit/7932b93fef7f0d92bf11ff1532fdc3fd3916d45c
https://github.com/facebook/react-native/releases
I’ve just personally confirmed it works for me after I upgraded react-native and removed the
postinstall
line from mypackage.json
@nerdmed The current solution is to add the following to your
scripts
section of yourpackage.json
file.If that’s not working for you, you might have another NPM that’s including a
.babelrc
that is tripping up React Native. I personally am surprised it’s not fixed yet, I’m currently on version 0.44.0@jpaas seavan is not refering to your .babelrc/.babelignore if I understand well. He refers to the .babelrc of the intl node module. It’s better explained in this discussion: https://github.com/andyearnshaw/Intl.js/pull/264
I went for the workaround they propose there: remove the .babelrc file of the intl module in the postinstall of your package.json, it works fine until a better solution is found.
What is the
intl
library doing that causes this? This issue description does not make it clear what is broken inside RN, just that something is wrong when you use this library. Please re-open an issue that is more specific about RN’s behavior, if the issue doesn’t already existHoping this gets merged in soon. Can’t currently run
./gradlew
without first runningrm -f node_modules/intl/.babelrc
, which requires me to update build scripts in our android deployment flow, that I’d rather not modify for a temp fix.@antoinerousseau remove all files from .babelignore or “ignore” section of “babelrc”. make sure they are transformed correctly.
https://github.com/andyearnshaw/Intl.js/pull/264