-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Should not inject import statement if module.exports statement exists #6980
Comments
Hey @trainiac! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
You are trying to make contradictory things.
So, maybe just set |
I've tried the combinations that you mention but there are problems with each of them.
It seems like no matter what there is no good solution. Anybody who has some commonjs files within there ES module application will not work with useBuiltins: "usage". I don't think this is that uncommon. |
Can you configure webpack to use Smth like: rules: [
{
test: /dir-with-es6modules-\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { modules: false }]],
}
}
},
{
test: /dir-with-commonjs-\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { modules: "commonjs" }]],
}
}
}
] |
This is a great idea. I do tend to prefer keeping my babel configuration in one file but this definitely achieves what I was looking for. @yavorsky Hats off to you sir |
Choose one: is this a bug report or feature request?
Bug
Input Code
Babel/Babylon Configuration (.babelrc, package.json, cli command)
Expected Behavior
If using "@babel/preset-env" with modules set to false and useBuiltins set to to usage, babel should not inject import statements for polyfills if the file has a module.exports statement because it doesn't work with webpack.
Current Behavior
polyfills get injected with import statements which causes webpack to generate code that generates a runtime error
Possible Solution
In this case just inject a requires statement instead of an import statement
Context
I'm trying to upgrade to babel 7
Your Environment
The text was updated successfully, but these errors were encountered: