-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
Warning if transpiling ES modules to commonjs #477
Comments
@jakearchibald based on the babel-preset-es2015 documentation you could set something like:
update: understood that the point is making it as a default behaviour, agree! |
Yeah, I used the same workaround, but since babel-loader is built for webpack, and webpack handles modules better than commonjs (eg tree shaking), it should be the default. Unless there's a reason users would want to transpile to commonjs before passing to webpack? |
Imho, this would break the predictability of both tools. Webpack and Babel are already hard to set up, and messing with the tools' defaults will probably cause a lot of unaware mistakes. Babel recommends to turn the option off when you want to delegate the modules' resolution to another tool. I think we should keep the option explicit, instead of having the tools to mess with the options behind the scenes. I do believe, however, that we could update the README.md examples to include that option, since like you stated, it does make sense to delegate the modules resolution to Webpack. |
Right, but you have to balance that with the unaware mistake of losing tree shaking without warning. Sure, you could add something to the readme along the lines of "btw a lot of the common defaults do the wrong thing", but a runtime warning sounds a lot more useful. |
If we don't mess with the option behind the scenes, and it just throws a warning, I think that's a cool feature. Would you be willing to do a PR? |
I'm really just learning webpack right now & creating issues as I find them as a user. I don't know how plugins are made (nor I'm I familiar with the internals of Babel), so it might be a while before I can ramp up to a decent PR. Eg, I'm sure there's a standard way to do logging, but I have no idea. But if no one knowledgeable is willing to take it, I guess I could get to it eventually. |
At the least, I think that providing a warning would be wonderful. @jakearchibald webpack supports more than one target. So we have to be as open as possible so that those who transpile esm to cjs for their node webpack bundles, can do so by default. However a warning is incredible beneficial. |
@TheLarkInn I guess the warning could only display for web targets? Maybe that isn't available to babel-loader. Anyway, I'll need to do isomorphic stuff for the thing I'm playing with, so I might be able to bring an informed opinion next week 😄 |
Yes totally!! Plz do. I mean, in a perfect world, loaders shouldn't directly access config options, but I believe they can (in some cases). |
@Couto @jakearchibald I could give it a spin as I believe this would be great. |
That's great! Ping if you have any questions I'm sure we all be happy to help! :D
…On June 23, 2017 6:48:40 PM GMT+02:00, Ward Peeters ***@***.***> wrote:
@Couto @jakearchibald I could give it a spin as I believe this would be
great.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#477 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
will start on this tomorrow 👍 |
When working with codebases that both use modules and commonjs, Good enough reason for me to not make this a default in babel-loader. See fx: webpack/webpack#4039 |
@woutervanvliet it will just be a warning and I guess most of the users will not have multiple types of imports |
@wardpeet Agree - not many, but some. Would imagine in particular some who might be in transition from the one to the other. Found out about it because I ran into this issue. Would be great if there was an easy, obvious way to suppress the warning. For example by specifying an explicit other option than false for the modules option. |
When webpack is version 2 or higher and we're using es2015 or env preset We throw a warning saying that webpack can't treeshake correctly Closes babel#477
When webpack is version 2 or higher and we're using es2015 or env preset We throw a warning saying that webpack can't treeshake correctly Closes babel#477
Yes we should be doing this. I will do the PR myself if I have to. There is no sensible reason to downgrade to cjs from esm if using webpack 2+ |
PR is still open.. You can always change things on my PR. |
@TheLarkInn My primary concern is that there's no guarantee that they will behave identically. Either Babel or Webpack could have bugs in their implementation. We've generally shied away from having build tools change behavior that hasn't been encoded into the user's config by the user themselves. |
PR #529 should fix this; instead of giving a warning it modifies the config to set |
This should be resolved with #660 in Babel 7.x |
Some presets, such as 'es2015' will transpile ES6 modules to commonjs. This works fine, but it prevents webpack performing treeshaking, meaning bundles could be unnecessarily larger.
Is there any reason users would want to transpile to commonjs at this point in the pipeline? If not, babel-loader could attempt to change the default here, or at least display a warning if it detects this kind of transpilation occurring.
The text was updated successfully, but these errors were encountered: