Bundle command does not add InitializeCore to runBeforeMainModule
See original GitHub issueBug report I was tracking a react native bug, but since my fix is inside metro code, I figured I repost here: https://github.com/facebook/react-native/issues/19827#issuecomment-404156181
What is the current behavior? When using react-native bundle (the command that runs when you build a release), InitializeCore.js is not the first file that get required, but instead it is required later, sometime during the generation of the bridge method, randomly (which is why if you are lucky or not using Promise // setTimeout early you’ll be fine) iOS does not need all those polyfills which is why the issue is only detected on android in release mode.
My insight: Metro does not add InitializeCore.js to the entry point when building the js bundle. I’ve logged here. The issue being that it takes options.runBeforeMainModule that defaults to []. Maybe we could merge it with _this._opts.getModulesRunBeforeMainModule() which defaults to [‘/node_modules/react-native/Libraries/Core/InitializeCore.js’].
I’ve tried to replace it with
runBeforeMainModule: [
...options.runBeforeMainModule,
..._this._opts.getModulesRunBeforeMainModule(),
],
and android was working in release 🎉
I’d like to get more insight from other people and feel free to ask any other question, thanks
To reproduce just create a new app with RN 0.56 and console.log(Promise) at the top of your index.js, you’ll get Promise is undefined when android release.
RN version: 0.56.0 and related metro version.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:9 (5 by maintainers)
Top GitHub Comments
Hey folks, https://github.com/facebook/metro/commit/64a5b1d9d40397899ca7eab69da62ee504ef4e54 has just landed with a fix for this. I’m going to cherry-pick this change to the
0.38.x
branch and publishmetro@0.38.3
Sorry for the inconvenience
Thanks for the report! @Titozzz your suggestion is correct, I’m going to prepare a fix for this