-
Notifications
You must be signed in to change notification settings - Fork 24.2k
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
[0.56][RELEASE] Bundler cuts off some used babel helpers in release build (decorators issue) #20150
Comments
@farwayer
|
@thientnc-ibl This is root |
The RELEASE build is OK now, bravo... We should write this work around to React native 0.56 doc |
RN includes its own version of babel-helpers but it does not include the |
I was stuck with this problem in my release build until I manually recreated the android bundle. I thought the bundle was recreated automaticly on release. But I had to run the terminal code after each change: 'react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/' |
Faced the same error with React Native 0.56, used combination of resolutions proposed including the Workaround 2 by @farwayer above. Steps that I followed:
rm -rf node_modules
yarn
yarn upgrade react-native@0.56.0
Check the version of babel components used with React Native by checking the
index.js import {AppRegistry} from 'react-native'
// RN 0.56 Release version crashes
// import App from './src/App'
// AppRegistry.registerComponent('MyApp', () => App)
// Workaround: RN 0.56 Release version crashes
// Sources:
// https://github.com/facebook/react-native/issues/19827
// https://github.com/facebook/react-native/issues/20150
import applyDecoratedDescriptor from '@babel/runtime/helpers/es6/applyDecoratedDescriptor'
import initializerDefineProperty from '@babel/runtime/helpers/es6/initializerDefineProperty'
Object.assign(babelHelpers, {applyDecoratedDescriptor, initializerDefineProperty})
// Your main app code is in /src/index.js
AppRegistry.registerComponent('MyApp', () => require('./src').default) Tested iOS / Android - Debug and Release version on Simulators and Devices. - All of them are working fine. Note: I am also using decorators for MobX and custom .babelrc package.json {
"name": "MyApp",
"version": "0.0.1",
"dependencies": {
"@babel/plugin-proposal-decorators": "7.0.0-beta.47",
"@babel/runtime": "7.0.0-beta.47",
"mobx": "^5.0.3",
"mobx-react": "^5.2.3",
"react": "16.4.1",
"react-native": "0.56.0"
},
"devDependencies": {
"babel-jest": "23.4.0",
"babel-preset-react-native": "^5",
"flow-bin": "^0.76.0",
"jest": "^23.4.1",
"jsc-android": "^224109.0.0",
"react-native-cli": "^2.0.1",
"react-test-renderer": "16.4.1"
},
"jest": {
"preset": "react-native"
}
} .babelrc {
"presets": [
"react-native"
],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
]
]
} |
With decorators plugin jest is broken too:
|
Your solution works flawlessly @farwayer. My |
This error also exists in React Native 0.57 rc3. |
This error also exists in React Native 0.57 rc3. |
In
This kinda explain why flow is affecting the babel output as describe around the issue… If you provide your own plugins, it get applied first before So, if you need decorators, you will have to place The fix for me is to add {
"plugins": [
[
"@babel/plugin-transform-flow-strip-types"
],
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
],
} |
For me none of the above solutions/workarounds work. |
SOLVED 🎉, thanks to @Amnesthesia @jrnk ❤️ oblador/react-native-vector-icons#801 (comment) Tested both ios/android debug/release (didn't upload to stores though but delivered with TestFairy so it should be just fine) |
Thank you guys!! You guys were save me! :) 👍 |
…erator (#198) Summary: **Summary** The RN transformer currently relies on the enviroment providing babelHelpers and regeneratorRuntime as globals by using 'babel-external-helpers'. This wasn't really a problem before since helpers were stable and we could maintain our copy easily but it seems like there are more now with babel 7 and it makes sense to include only those used by the app. This is exactly what babel/transform-runtime does. It will alias all helpers and calls to regeneratorRuntime to files in the babel/runtime package. This will solve issues like this facebook/react-native#20150 caused by missing babelHelpers. This solution also avoids bloating babelHelpers to fix OSS issues like the one linked before. **Test plan** - Updated tests so they all pass. - Tested that it actually works by applying the changes locally in an RN app. - Added a test for async functions, to make sure regenerator is aliased properly and doesn't depend on the global. - Made sure require-test.js still fails if the require implementation contains babel helpers (by adding an empty class in the file). Pull Request resolved: #198 Reviewed By: mjesun Differential Revision: D8833903 Pulled By: rafeca fbshipit-source-id: 7081f769f288ab358ba89ae8ee72a513bb12e225
…erator (#198) Summary: **Summary** The RN transformer currently relies on the enviroment providing babelHelpers and regeneratorRuntime as globals by using 'babel-external-helpers'. This wasn't really a problem before since helpers were stable and we could maintain our copy easily but it seems like there are more now with babel 7 and it makes sense to include only those used by the app. This is exactly what babel/transform-runtime does. It will alias all helpers and calls to regeneratorRuntime to files in the babel/runtime package. This will solve issues like this #20150 caused by missing babelHelpers. This solution also avoids bloating babelHelpers to fix OSS issues like the one linked before. **Test plan** - Updated tests so they all pass. - Tested that it actually works by applying the changes locally in an RN app. - Added a test for async functions, to make sure regenerator is aliased properly and doesn't depend on the global. - Made sure require-test.js still fails if the require implementation contains babel helpers (by adding an empty class in the file). Pull Request resolved: facebook/metro#198 Reviewed By: mjesun Differential Revision: D8833903 Pulled By: rafeca fbshipit-source-id: 7081f769f288ab358ba89ae8ee72a513bb12e225
This comment has been minimized.
This comment has been minimized.
@rknell Sorry you are feeling this way. This took a long time to fix since it isn't a hacky patch and required major changes in the way RN handles babel helpers so we don't rely on manually adding them anymore. A patch to move from global Thanks for you patience on this one. |
This comment has been minimized.
This comment has been minimized.
…erator (#198) Summary: **Summary** The RN transformer currently relies on the enviroment providing babelHelpers and regeneratorRuntime as globals by using 'babel-external-helpers'. This wasn't really a problem before since helpers were stable and we could maintain our copy easily but it seems like there are more now with babel 7 and it makes sense to include only those used by the app. This is exactly what babel/transform-runtime does. It will alias all helpers and calls to regeneratorRuntime to files in the babel/runtime package. This will solve issues like this #20150 caused by missing babelHelpers. This solution also avoids bloating babelHelpers to fix OSS issues like the one linked before. **Test plan** - Updated tests so they all pass. - Tested that it actually works by applying the changes locally in an RN app. - Added a test for async functions, to make sure regenerator is aliased properly and doesn't depend on the global. - Made sure require-test.js still fails if the require implementation contains babel helpers (by adding an empty class in the file). Pull Request resolved: facebook/metro#198 Reviewed By: mjesun Differential Revision: D8833903 Pulled By: rafeca fbshipit-source-id: 7081f769f288ab358ba89ae8ee72a513bb12e225
Did you resolve?
|
To be honest, I had to hardcode versions beta.47 of the relevant babel packages in order to get it to work. Upgrading to 7.1.2 didn't help. |
for me I need |
This issue seams to be solved in 0.57.4 (60b05ca). We can go back to:
|
Getting the same on updating from 0.55 to 0.58.6 Edit: For me, just a --reset-cache for packager solved it, been working with a copy using 0.55 as well, not sure if that created an issue the second time around.... |
I've tried to understand the workarounds here and if they're still needed or not. I'm running RN using Expo v32.0, and I'm heavily invested in decorators (due to MobX), and I'm getting this error when trying to run the production version. What do I do? I'm not using Update: Finally got it up and running again. Not entirely sure what fixed it in the end, but I upgraded from Babel 6 -> 7 and this is what my babel.config.js looks like:
I also cleared Expo cache multiple times ( |
…erator (facebook#198) Summary: **Summary** The RN transformer currently relies on the enviroment providing babelHelpers and regeneratorRuntime as globals by using 'babel-external-helpers'. This wasn't really a problem before since helpers were stable and we could maintain our copy easily but it seems like there are more now with babel 7 and it makes sense to include only those used by the app. This is exactly what babel/transform-runtime does. It will alias all helpers and calls to regeneratorRuntime to files in the babel/runtime package. This will solve issues like this facebook/react-native#20150 caused by missing babelHelpers. This solution also avoids bloating babelHelpers to fix OSS issues like the one linked before. **Test plan** - Updated tests so they all pass. - Tested that it actually works by applying the changes locally in an RN app. - Added a test for async functions, to make sure regenerator is aliased properly and doesn't depend on the global. - Made sure require-test.js still fails if the require implementation contains babel helpers (by adding an empty class in the file). Pull Request resolved: facebook#198 Reviewed By: mjesun Differential Revision: D8833903 Pulled By: rafeca fbshipit-source-id: 7081f769f288ab358ba89ae8ee72a513bb12e225
…erator (#198) Summary: **Summary** The RN transformer currently relies on the enviroment providing babelHelpers and regeneratorRuntime as globals by using 'babel-external-helpers'. This wasn't really a problem before since helpers were stable and we could maintain our copy easily but it seems like there are more now with babel 7 and it makes sense to include only those used by the app. This is exactly what babel/transform-runtime does. It will alias all helpers and calls to regeneratorRuntime to files in the babel/runtime package. This will solve issues like this facebook#20150 caused by missing babelHelpers. This solution also avoids bloating babelHelpers to fix OSS issues like the one linked before. **Test plan** - Updated tests so they all pass. - Tested that it actually works by applying the changes locally in an RN app. - Added a test for async functions, to make sure regenerator is aliased properly and doesn't depend on the global. - Made sure require-test.js still fails if the require implementation contains babel helpers (by adding an empty class in the file). Pull Request resolved: facebook/metro#198 Reviewed By: mjesun Differential Revision: D8833903 Pulled By: rafeca fbshipit-source-id: 7081f769f288ab358ba89ae8ee72a513bb12e225
Environment
Description
Bundler cuts off some used babel helpers in release build. Look like by mistake while optimization.
For example
initializerDefineProperty
andapplyDecoratedDescriptor
needed by@babel/proposal-decorators
.Reproducible Demo
Workaround 1 (can have side effects)
Be care because this workaround can bring some errors with external libs.
For RN 0.56:
.babelrc
For RN 0.57:
.babelrc
Workaround 2
Move app initialization to some other file (I'm using
src/
dir for source) and update rootindex.js
file.N.B.
require
main app code instead ofimport
becauserequire
executed after.For RN 0.56:
Root
index.js
For RN 0.57:
Root
index.js
The text was updated successfully, but these errors were encountered: