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

Make sure we work with Babel 7 #411

Closed
thymikee opened this issue Apr 22, 2018 · 18 comments
Closed

Make sure we work with Babel 7 #411

thymikee opened this issue Apr 22, 2018 · 18 comments
Labels

Comments

@thymikee
Copy link
Member

RN recently merged Babel 7 into master, which means v0.56 will probably get this – @grabbou correct me if I'm wrong.
Would be good to make sure we support that (probably some documentation changes and installing [email protected] will do).

@thymikee thymikee added the 1.x label Apr 22, 2018
@krizzu
Copy link
Contributor

krizzu commented Apr 22, 2018

So that means react-native preset is already upgraded? If so, we could try to use B7 now

@thymikee
Copy link
Member Author

thymikee commented Apr 22, 2018

@hedgepigdaniel
Copy link
Contributor

Not sure exactly where I've ended up, but I tried to upgrade a project to babel 7 and ended up with this error:

./app/index.android.js
Module build failed: Error: Unknown substitution APP_REGISTRATION given
   at app/node_modules/@babel/template/lib/populate.js:32:15
   at Array.forEach (<anonymous>)
   at populatePlaceholders (app/node_modules/@babel/template/lib/populate.js:30:31)
   at app/node_modules/@babel/template/lib/string.js:22:51
   at app/node_modules/@babel/template/lib/builder.js:85:14
   at programPath.node.body.push.createHmrLogic.map.partial (app/node_modules/haul/src/hot/babelPlugin.js:211:9)
   at Array.map (<anonymous>)
   at applyHmrTweaks (app/node_modules/haul/src/hot/babelPlugin.js:210:35)
   at PluginPass.ImportDeclaration (app/node_modules/haul/src/hot/babelPlugin.js:235:11)
   at newFn (app/node_modules/@babel/traverse/lib/visitors.js:243:21)
   =============
   at codeSnippets.map.snippet (app/node_modules/haul/src/hot/babelPlugin.js:45:38)
   at Array.map (<anonymous>)
   at createHmrLogic (app/node_modules/haul/src/hot/babelPlugin.js:45:23)
   at applyHmrTweaks (app/node_modules/haul/src/hot/babelPlugin.js:210:10)
   at PluginPass.ImportDeclaration (app/node_modules/haul/src/hot/babelPlugin.js:235:11)
   at newFn (app/node_modules/@babel/traverse/lib/visitors.js:243:21)
   at NodePath._call (app/node_modules/@babel/traverse/lib/path/context.js:65:18)
   at NodePath.call (app/node_modules/@babel/traverse/lib/path/context.js:40:17)
@ multi ./node_modules/haul/src/utils/polyfillEnvironment.js ./app/index.android.js

@thymikee
Copy link
Member Author

thymikee commented Apr 30, 2018

Haul does not support Babel 7 yet.

@jshearer
Copy link

RN 0.56 RC is out. Does Haul support Babel 7 yet?

@danielkcz
Copy link

danielkcz commented Jun 16, 2018

@jshearer You know, bumping often won't make things magically happen ;) Also considering it's still just an RC version, you should be prepared that another tech hasn't really caught up to it yet. Bleeding edge is dangerous and you have to live with consequences of that choice ... or help out instead perhaps?

Out of curiosity, you have switched back to metro? So why are you using Haul in a first place if you don't need any features of Webpack really?

@deepsweet
Copy link
Contributor

deepsweet commented Jul 5, 2018

RN 0.56 release with Babel 7 has just landed.

I've tried to fork Haul to use Babel 7, changed all the dependencies, tweaked everything in src/babelRegister.js and src/cli.js but fall into a rabbit hole of red screens, step by step. It's hard to do that without knowing all the internals and workarounds.

Dear collaborators, sorry for pinging again with this issue, but is there any estimations on integrating Babel 7 to Haul? I'd help.

@thymikee
Copy link
Member Author

thymikee commented Jul 5, 2018

@deepsweet thanks for your help! Plugins used in Webpack config (especially babel-loader) also need to be updated and we probably need to add a peerDependency on babel-core ^6.0.0 || 7.0.0-0. Can you try that?

@tkow
Copy link

tkow commented Jul 6, 2018

@thymikee I have same issue and tried adding a peerDependency babel-core ^6.0.0 || 7.0.0-0
to package.json at node_modules/haul and npm install --no-dev at node_modules/haul, then react-native run-ios with starting haul but it doesn't work and error says:

./node_modules/haul/src/vendor/polyfills/Number.es6.js                                                                                                                                                                                                                                                                        
Module build failed (from ./node_modules/haul/node_modules/babel-loader/lib/index.js):     

and may be related to bridge older version release note says.

In addition, haul's stdout.log says:

Error: Plugin 0 specified in "{$project}/node_modules/babel-preset-react-native/index.js" provided an invalid property of "default" (While processing preset: "{$project}/node_modules/babel-preset-react-native/index.js")
    at Plugin.init ({$project}/node_modules/haul/node_modules/babel-core/lib/transformation/plugin.js:131:13)
    at Function.normalisePlugin ({$project}/node_modules/haul/node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
    at {$project}/node_modules/haul/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
    at Array.map (<anonymous>)
    at Function.normalisePlugins ({$project}/node_modules/haul/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
    at OptionManager.mergeOptions ({$project}/node_modules/haul/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
    at {$project}/node_modules/haul/node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
    at {$project}/node_modules/haul/node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets ({$project}/node_modules/haul/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)

this errors may be related to however modules are imported though I don't find conclusion.
I saw these discussions as clues

especially, facebook/react-native@6de4ff3
says RN changes, I wonder if metro-babel7-plugin-react-transform have side effects though I don't have confidence.

and our error may happen by difference of exports.default and module.exports react-native-maps/react-native-maps#1970

We really want to fix this because we use typescript.
If we can webpack-loader loosely-coupled and like addon plugins.
Do Anyone have idea to fix this?

@ErrorPro
Copy link

ErrorPro commented Jul 9, 2018

Just “babel-preset-react-native”: “4.0.0", made it work for me. Do it inside your project.

npm i [email protected]

@tkow
Copy link

tkow commented Jul 9, 2018

@ErrorPro

About https://github.com/facebook/react-native/releases/tag/v0.56.0,

When upgrading to 0.56, make sure to bump your babel-preset-react-native package.json dependency to ^5.0.1 or newer.

Does “babel-preset-react-native”: “4.0.0" work with RN 0.56?

I tried version 5.0.1 before but it didn't. I'll try again with 4.0.0.

@ErrorPro
Copy link

@tkow I created a new RN project using react-native init and then just downgraded babel-preset-react-native plugin and it worked for me. Please notice: I use haul only to build release bundle, for development I still use metro.

@tkow
Copy link

tkow commented Jul 11, 2018

@ErrorPro We understood the point about capacity of the version compatibility of old babel preset
because babel 7 core has backward compatibility about old preset (If it doesn't, we can bridge), but I wonder if downgrade babel-preset may have risk about lack of RN bridge or other core codes. Anyway, Thank you for comments.
We decided older version until solution are found by anyone, or I'll survey and try to fix if I can.

@tkow
Copy link

tkow commented Aug 17, 2018

I found that this problem derived from babel-preset-react-native version, now renamed metro-react-native-babel-preset. I rewrote babel-preset react-native to module:metro-react-native-babel-preset with installing the latest in my .babelrc and use babel-loader for babel 7, then it failed resolving NativeModules though any other modules looks no error. There may be problem of metro-react-native-babel-preset.

@grabbou
Copy link
Member

grabbou commented Aug 20, 2018 via email

@tkow
Copy link

tkow commented Sep 6, 2018

I ran

npx babel-upgrade --write

and can use [email protected] with haul1.0.0-rc.7. so we can use old babel-preset with babel-core7 bridge anyway though it seems obvious, anyway I wait future news.

In Addition: I have old babel cache so we cannot repro build success.

@hedgepigdaniel
Copy link
Contributor

I've managed to get a project working with Haul + React Native 0.57 + Babel 7 stable. Here's the current progress: #477

@thymikee
Copy link
Member Author

closed via #477

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants