-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Enable babel-preset-env for node_modules that target newer Node versions #1125
Comments
No, this is not supported because builds will get much slower. We don't recommend using libraries that don't precompile their code to ES5 but are supposed to be usable in ES5. We will fix the Uglify problem in the future by using Babili. However it still means that even uglified code will still be ES6 if that's what your dependencies are shipping. With time it won't matter as much because mainstream browsers will support ES6. Until then I recommend to use libraries that take care of transpilation step. |
I understand but it creates a dichotomy between Node's and browsers' worlds, which will lead to less isomorphic JavaScript components/libraries :/ @sindresorhus, you have migrated many of your packages to ES2015, what's your opinion on this? And, once Uglify as been replaced by Babili, I'm not sure it'll have a big impact to add other Babel presets to the compilation pass (@hzoo, any inputs on this?) |
Concerning the perf impact, I guess it depends of how many times the code is parsed/generated, it would be interesting to have everything done in a single one but it probably depends on the bundler (Webpack). |
OK, let’s keep it open and wait for more feedback. The cold start time is pretty bad. I saw an increase from 6 to 20 seconds on a relatively small app. However, since we enable caching for Babel loader, warm start stays 6 second. |
I would be comfortable doing this if:
|
I understand very well your pain about long compile time, but I think the answer is somewhere because with bundling, tree-shaking and minification, this code is already parsed. Maybe the work is more on the ecosystem side (Babel, Webpack, etc.) to avoid doing unnecessary operations (parsing and generation). |
Running babel on all of node_modules does sound really slow - right it might be faster (would need to measure) passing an AST to webpack or vice versa. |
@hzoo but if Babili is used, the code won't get much slower by adding other Babel plugins/presets right? At least much faster that Babel + Uglify. |
To be fair there is no minification in development. |
Seems logic, but watch mode may be enough to mitigate the issue… |
At this point I’m more concerned about correctness than speed. |
Yes, that's the main issue. I don't know if running Babel on external deps is a good idea, but I fear the problem of incompatible deps will continue to grow, and fast. :/ |
I think this should be on the library authors because they know which JS version they wrote code in, and they can spend their CPU once every release so that other people don’t have to waste their CPU compiling their libraries. It is not difficult to compile JS code to ES5 as a build step, with Babel it's literally a single command. And they can always provide multiple versions (e.g. |
Yes, but they might do this because it's easier, or because the code is faster (generators, async functions) if not transpiled, or simply because they did not thought about the use of their code in something else than Node. They also might say that it's up to the consumers to compile because only them know which JS version they target ;) @sindresorhus, when you have time, I would love to have your opinion on this :) |
I think it's really weird to be compiling node_modules. Libraries/packages should be compiling themselves or at least providing an optional es5 version? This is also what caused babel/babylon#154 - where you would have an issue in 3rd party code |
The problem is the shifting baseline. Why are we using ES5 as a baseline? Because it was the lowest common denominator. But it’s shifting, and it won’t make sense to still use ES5 as lowest common denominator in 10 years. So the question is: when should the lowest common denominator shift to ES6? I don’t think the answer is now, and I also don’t think it’s a good idea to compile ES6 code in dependencies. It’s just asking for random breakage. I think it’s up to dependencies to declare which environments they support, and if they choose to ship ES6 as |
Maybe the user could configure a list of packages to compile? |
I think you're asking too much of module maintainers. I target Node.js 4 for modules I make. If users wants them to run in older browsers, it's up to them to transpile. I'm not interested in having a compile step in all my modules. Maybe there could be a Babel feature (or another tool) that checks the "engine" package.json field in dependencies and decides which dependencies to transpile. Caching should also help, so a dependency is only transpiled once and cached forever for that version. I've expanded on my answer here: sindresorhus/ama#446 |
Wouldn't that be more of a |
I use {
test: /\.js$/,
include: [
paths.app,
path.resolve(paths.node_modules, 'cron-parser')
],
loader: 'babel-loader',
// ... other options
} I think if you only care about node, setting up the tools and tranpsiling is actually a solid barrier, especially if you're unfamiliar with the overall ecosystem. First you need to get babel-cli and babel-preset-env. If you look at the docs you might ask yourself: should I enable that"loose" mode thing? Then, depending on what features you're using, you might need to grab babel-plugin-transform-runtime and babel-runtime, figure out what their options do, and which ones you might need to turn on / off. I don't think it's complicated once you're familiarized with the tooling, but there's still room for stumbling. Oh, and the end result usually means replacing the regular main field version with the harder to debug equivalent. :( |
That's not so bad, maybe it should be exposed a nicer way in create-react-app. |
@gaearon how can i backport this to a |
The problem IMHO is that different people/companies have very different expectations for what is the baseline. If you are supporting 1000s of devs for a "modern" npm library (as my own) then your baseline won't be ES5, it'll be ES6 already. If you are a company with millions (or billions) of users, or worse you are developing for Japan (as I do) then you definitely need to support IE and ES5. Same as if you use Electron, etc. I normally do the export with UMD because I like being able to When you have 10s or 100s of repositories/npm libraries, every extra, optional step counts towards maintainability and bandwidth. Edit: so, thanks for adding support! |
Is there a solution for those who haven't ejected as of now? My issue was with |
Update react scripts, Latest version supports your scenario but there might be some problem as they are still in alpha version |
This shipped in 2.0. |
Hello, I'm experimenting with this new feature by substituting all of my named exports from The app starts just fine with create-react-app v2, but I am unable to run jest tests, as it's breaking on the es6 imports and exports:
What is the correct way to address this? Should I add a custom Jest configuration file |
@nerfologist please file a new issue |
Hello,
More and more npm packages contain ES2015+ code (for now usually features supported by Node 4 but i guess it will move to Node 6 features once 4 will be unmaintained). Unfortunately, this breaks compatibility with Uglify and browsers.
The only answer to this is, IMHO, to also transpile external dependencies. Is this supported by create-react-app?
I'm asking because my own build set up is getting confronted to this and I'm thinking about migrating to create-react-app :)
The text was updated successfully, but these errors were encountered: