question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Packager not handling .babelignore'd files due to sourcemap generation logic

See original GitHub issue

Description

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 https://github.com/facebook/react-native/issues/12071

I’ve chatted with @loganfsmyth from BabelJS and his comments were:

cool, I think this is a regression in react-native, their code in that stacktrace is not handling ignored files: https://github.com/facebook/react-native/blob/master/packager/transformer.js#L110, ast will be undefined if the file was ignored (edited) I believe that code was added recently for their faster sourcemap generation logic

Reproduction Steps and Sample Code

A project running 0.43.0-rc4 which produces a more verbose error than 0.42 does is here:

https://github.com/kevinold/RNBabelIgnoreIssue

Upon running react-native run-ios the following error is produced:

error: bundling: TypeError: Cannot read property 'tokens' of undefined
    at new Generator (/Users/kold/eval-projects/RNBabelIgnoreIssue/node_modules/babel-generator/lib/index.js:51:21)
    at exports.default (/Users/kold/eval-projects/RNBabelIgnoreIssue/node_modules/babel-generator/lib/index.js:19:13)
    at Object.transform (/Users/kold/eval-projects/RNBabelIgnoreIssue/node_modules/react-native/packager/transformer.js:110:20)
    at transformCode (/Users/kold/eval-projects/RNBabelIgnoreIssue/node_modules/react-native/packager/src/JSTransformer/worker/worker.js:91:31)
    at exports.transformAndExtractDependencies (/Users/kold/eval-projects/RNBabelIgnoreIssue/node_modules/react-native/packager/src/JSTransformer/worker/worker.js:148:3)
    at handle (/Users/kold/eval-projects/RNBabelIgnoreIssue/node_modules/worker-farm/lib/child/index.js:41:8)
    at process.<anonymous> (/Users/kold/eval-projects/RNBabelIgnoreIssue/node_modules/worker-farm/lib/child/index.js:47:3)
    at emitTwo (events.js:106:13)
    at process.emit (events.js:194:7)
TransformError: /Users/kold/eval-projects/RNBabelIgnoreIssue/epublican-native-context-opt.js: Cannot read property 'tokens' of undefined
Bundling `index.ios.js`  99.0% (403/405), failed.

Solution

Handle babel ignored (in .babelrc ignore sections or .babelignore) files in the packager: https://github.com/facebook/react-native/blob/master/packager/transformer.js#L110

Additional Information

  • React Native version: Broken: 0.42-0.43.0-rc4, works on 0.41
  • Platform: iOS (I assume Android too)
  • Development Operating System: OS X El Capitan

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kevinoldcommented, Apr 26, 2017

As a workaround I am using haul to package my app with my ignored files in .babelrc instead of a .babelignore like so:

{
  "presets": ["react-native"],
  "ignore": [
    "my-ignored-lib.js"
  ]
}
0reactions
sujitpk-perennialcommented, Jul 12, 2018

@alexanderkjeldaas @GarimaMathur07 I am also getting JavaScript heap out of memory issue for large file. How you resolved this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found