React-native: Cannot read property 'tokens' of undefined

Created on 25 Jan 2017  路  23Comments  路  Source: facebook/react-native

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]
Locked

Most helpful comment

@ericvicenti please reopen the issue

All 23 comments

caused by this commit https://github.com/facebook/react-native/commit/0849f84df26e4c56f5763375363bae90d94015fe I hope @davidaurelio can give me a hint since I'm not fully understand this patch.

I 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.

The issue is solved in the version 0.41, it can be closed.

@gitim I am getting this again in 0.42-rc2.
It does work on 0.41.

Also getting this on 0.42.0-rc3, and confirmed working downgrading to 0.41.0.

Just encountered this problem in 0.42.0 release. 0.41 works fine.

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 exist

@ericvicenti: This error occurs during packaging, not while using the library.

@ericvicenti please reopen the issue

probably related to #12695

any workaround idea?

@antoinerousseau remove all files from .babelignore or "ignore" section of "babelrc".
make sure they are transformed correctly.

@seavan that did the trick, thanks!

@seavan 's suggestion doesn't work for me because I don't have anything being ignored. So this continues to prevent me from moving up to 0.42

@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.

React-packager tries to parse .babelrc and .babelignore in node_modules as well as in the source directories. So yeah, if you have a NPM module which has .babelrc with "ignore" - you'll have problems.

When we have such problems we do it like this:

  • add a copy/watch task for that specific module, so on build it will copy all sources (or distro) "node_modules/some-specific-package/" to, say "app/lib/some-specific-package/"

That actually is enough. Your task won't copy '.babelrc', your packager won't try to parse it (unless you reference it as import 'package-name'; instead of import './lib/package-name';

Or as @didaKtik wrote, just add "postinstall": "rm -f node_modules/intl/.babelrc" to your package.json as proposed in https://github.com/andyearnshaw/Intl.js/pull/264

Ah thank-you @didaKtik that makes more sense. Well at least we have a workaround for now.

Hoping this gets merged in soon. Can't currently run ./gradlew without first running rm -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.

Any news here? Seems that this is still broken and its not the intl lib?!

@nerdmed The current solution is to add the following to your scripts section of your package.json file.

"postinstall": "rm -f node_modules/intl/.babelrc"

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

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 my package.json

Was this page helpful?
0 / 5 - 0 ratings