Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

fix babelrc #264

Closed
wants to merge 1 commit into from
Closed

Conversation

skv-headless
Copy link

My problem described here facebook/react-native#12071.

Babel can't handle lib/core.js file if filename option passed because babel is using your .babelrc.

var res = babel.transform(file, { code: false, filename: './node_modules/intl/lib/core.js', });

I'm not sure why do you need ignore in .babelrc

@skv-headless
Copy link
Author

@andyearnshaw what do you think?

@caridy
Copy link
Collaborator

caridy commented Jan 30, 2017

@skv-headless the source code for this pkg is in src/, not in lib/ or dist/, those are the compiled version of the source for node and browser respectively, and this compilation is done with babel, and we don't want babel to look at the compiled files, that's why those two folders are ignored.

@caridy caridy closed this Jan 30, 2017
@chirag04
Copy link

chirag04 commented Feb 14, 2017

@skv-headless did you figure out the solution here?

@skv-headless
Copy link
Author

I've added rm -f node_modules/intl/.babelrc to postinstall. But I'm not proud about it.

@chirag04
Copy link

chirag04 commented Mar 4, 2017

@caridy in RN environment, babel does look at node_modules. Here, package.json is having index.js as the main file which refers to the code in lib. So in RN env, lib is the src of truth. So ignoring lib breaks in RN environment.

I see two options here: 1) Either we npmignore the babelrc file or 2) we remove the ignore for lib. I think option 1 makes more sense.

it would be nice to not add a postinstall in my project for removing the babelrc. And thanks for the awesome lib. 👍

@hey99xx
Copy link

hey99xx commented Mar 7, 2017

Option 1) makes sense, I don't even know why 2) is an option at all. caridy is saying the file is already transformed during build process, why can't babel handle this correctly? From the issue linked above, this looks to be a bug in react-native packager 0.42 and above.

@caridy
Copy link
Collaborator

caridy commented Mar 30, 2017

Went with option 1), thanks everyone for the suggestions.

@huhuanming
Copy link

huhuanming commented Mar 31, 2017

try this in React Native.

if (!global.Intl) {
  global.Intl = require('intl/lib/core')
}

But not work in Release Version.

Sadly...

@caridy
Copy link
Collaborator

caridy commented Mar 31, 2017

@huhuanming we haven't release a new version yet, you will have to build from source to try this out today.

@huhuanming
Copy link

thank you.

@chirag04
Copy link

chirag04 commented Apr 6, 2017

@caridy can we get a new release?

budde377 added a commit to laundree/app that referenced this pull request Apr 23, 2017
budde377 added a commit to laundree/app that referenced this pull request Apr 23, 2017
budde377 added a commit to laundree/app that referenced this pull request Apr 23, 2017
@nenti
Copy link

nenti commented May 18, 2017

Can we get a new npm version please.

@borisyankov
Copy link

Yes, please.
Until you publish a new version on npm, this fix does not 'exist'.

@efkan
Copy link

efkan commented May 29, 2017

I code a React-Native (v0.44.2) project on node.js (v7.10.0) on an Ubuntu based OS.

I've encountered node_modules/intl/lib/core.js: Cannot read property 'tokens' of undefined exception too.

I tried adding the line of "postinstall": "rm -f node_modules/intl/.babelrc" in scripts block in packages.json.

Also I tried to remove and to add the line of "lib/*.js" in ignore block in node_modules/intl/.babelrc file.

And also I've tried to add this ignore block to my root .babelrc file like the below:

{
  "presets": ["react-native"],  
  "ignore": [
      "intl/dist/*.js",
      "intl/lib/*.js",
      "intl/locale-data/*.js"
  ]
}

However I couldn't overcome the issue. Is there any solution you know?

Loading dependency graph, done.
error: bundling: TypeError: Cannot read property 'tokens' of undefined
    at new Generator (/home/user/Projects/emsand/node_modules/babel-generator/lib/index.js:51:21)
    at exports.default (/home/user/Projects/emsand/node_modules/babel-generator/lib/index.js:19:13)
    at Object.transform (/home/user/Projects/emsand/node_modules/react-native/packager/transformer.js:110:20)
    at transformCode (/home/user/Projects/emsand/node_modules/react-native/packager/src/JSTransformer/worker/worker.js:91:31)
    at exports.transformAndExtractDependencies (/home/user/Projects/emsand/node_modules/react-native/packager/src/JSTransformer/worker/worker.js:148:3)
    at handle (/home/user/Projects/emsand/node_modules/worker-farm/lib/child/index.js:41:8)
    at process.<anonymous> (/home/user/Projects/emsand/node_modules/worker-farm/lib/child/index.js:47:3)
    at emitTwo (events.js:106:13)
    at process.emit (events.js:194:7)
TransformError: /home/efkan/Projects/emsand/node_modules/intl/lib/core.js: Cannot read property 'tokens' of undefined
Bundling `index.android.js`  87.6% (586/626), failed.

@piuccio
Copy link

piuccio commented May 29, 2017

@efkan after deleting node_modules/intl/.babelrc did you restart the packager? Close the terminal and react-native run-android

@efkan
Copy link

efkan commented May 29, 2017

@piuccio it works. Thank you a lot.

telldus-bot pushed a commit to telldus/telldus-live-mobile-v3 that referenced this pull request Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants