Skip to content
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

Cannot read property 'tokens' of undefined #12071

Closed
skv-headless opened this issue Jan 25, 2017 · 23 comments
Closed

Cannot read property 'tokens' of undefined #12071

skv-headless opened this issue Jan 25, 2017 · 23 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@skv-headless
Copy link
Contributor

skv-headless commented Jan 25, 2017

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]
@skv-headless
Copy link
Contributor Author

caused by this commit 0849f84 I hope @davidaurelio can give me a hint since I'm not fully understand this patch.

@gitim
Copy link
Contributor

gitim commented Jan 25, 2017

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.

@skv-headless
Copy link
Contributor Author

andyearnshaw/Intl.js#264

@gitim
Copy link
Contributor

gitim commented Feb 8, 2017

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

@ruiaraujo
Copy link
Contributor

ruiaraujo commented Feb 14, 2017

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

@dkpalmer
Copy link

dkpalmer commented Feb 14, 2017

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

@cknitt
Copy link

cknitt commented Mar 1, 2017

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

@ericvicenti
Copy link
Contributor

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

@cknitt
Copy link

cknitt commented Mar 1, 2017

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

@seavan
Copy link

seavan commented Mar 2, 2017

@ericvicenti please reopen the issue

@chandu0101
Copy link
Contributor

probably related to #12695

@antoinerousseau
Copy link
Contributor

any workaround idea?

@seavan
Copy link

seavan commented Mar 6, 2017

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

@antoinerousseau
Copy link
Contributor

@seavan that did the trick, thanks!

@jpaas
Copy link

jpaas commented Mar 8, 2017

@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

@pmdida
Copy link

pmdida commented Mar 9, 2017

@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: andyearnshaw/Intl.js#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.

@seavan
Copy link

seavan commented Mar 9, 2017

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';

@antoinerousseau
Copy link
Contributor

antoinerousseau commented Mar 9, 2017

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

@jpaas
Copy link

jpaas commented Mar 9, 2017

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

kevinold pushed a commit to kevinold/react-native that referenced this issue Apr 27, 2017
facebook-github-bot pushed a commit that referenced this issue May 8, 2017
Summary:
- [x] Explain the **motivation** for making this change.
- [x] Provide a **test plan** demonstrating that the code is solid.
- [x] Match the **code formatting** of the rest of the codebase.
- [x] Target the `master` branch, NOT a "stable" branch.

I have a need to bundle a pre-optimized external lib with my RN application. Until RN 0.42 I had been using a .babelignore to prevent the packager from trying to optimize this file and choke.

It seems in 0.42 and higher I'm no longer allowed to ignore the file.

This issue has also been reported as #12071

Details on the reasoning for this patch can be found in the issue I originally filed: #13168

What existing problem does the pull request solve?

This PR restores the functionality with babel ignoring files that existed in 0.41 before this patch:

0849f84#diff-4676ea0b3c55c65c3929aa993144f07f

Here's a screenshot of this patch properly ignoring the file I referenced in #13168 to be ignored.

![screen shot 2017-04-27 at 12 48 32 am](https://cloud.githubusercontent.com/assets/21967/25469653/524dbc0c-2ae3-11e7-81a6-faca2f4d21fe.png)

The patch relies on the `ignored` value of the call to `babel.transform` and if true returns the src in a object per instruction from loganfsmyth from BabelJS core team.

To test, add a file to the `ignore` array of a `.babelrc` file in a React Native project with this fork.

I was unable to locate a test file for the transformer.js

Fixes #12071, #13168
Closes #13681

Differential Revision: D5017565

Pulled By: davidaurelio

fbshipit-source-id: 421f57b5ce192eedd46fae4285d8a741cb5f8e71
makadaw pushed a commit to makadaw/react-native that referenced this issue May 9, 2017
Summary:
- [x] Explain the **motivation** for making this change.
- [x] Provide a **test plan** demonstrating that the code is solid.
- [x] Match the **code formatting** of the rest of the codebase.
- [x] Target the `master` branch, NOT a "stable" branch.

I have a need to bundle a pre-optimized external lib with my RN application. Until RN 0.42 I had been using a .babelignore to prevent the packager from trying to optimize this file and choke.

It seems in 0.42 and higher I'm no longer allowed to ignore the file.

This issue has also been reported as facebook#12071

Details on the reasoning for this patch can be found in the issue I originally filed: facebook#13168

What existing problem does the pull request solve?

This PR restores the functionality with babel ignoring files that existed in 0.41 before this patch:

facebook@0849f84#diff-4676ea0b3c55c65c3929aa993144f07f

Here's a screenshot of this patch properly ignoring the file I referenced in facebook#13168 to be ignored.

![screen shot 2017-04-27 at 12 48 32 am](https://cloud.githubusercontent.com/assets/21967/25469653/524dbc0c-2ae3-11e7-81a6-faca2f4d21fe.png)

The patch relies on the `ignored` value of the call to `babel.transform` and if true returns the src in a object per instruction from loganfsmyth from BabelJS core team.

To test, add a file to the `ignore` array of a `.babelrc` file in a React Native project with this fork.

I was unable to locate a test file for the transformer.js

Fixes facebook#12071, facebook#13168
Closes facebook#13681

Differential Revision: D5017565

Pulled By: davidaurelio

fbshipit-source-id: 421f57b5ce192eedd46fae4285d8a741cb5f8e71
@ghost
Copy link

ghost commented May 23, 2017

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.

@nerdmed
Copy link

nerdmed commented Jun 15, 2017

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

@ghost
Copy link

ghost commented Jun 16, 2017

@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

@ghost
Copy link

ghost commented Jun 16, 2017

Looks like it was fixed in 0.45.1

7932b93

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

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests