parcel: Unexpected "With `useBuiltins` option, required direct setting of `corejs` option" with default configuration
🐛 bug report
Calling parcel build <entry point> with all default configuration results in a warning from @babel/preset-env.
🎛 Configuration (.babelrc, package.json, cli command)
.babelrc: nonepackage.json:
{
"name": "test",
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"parcel-bundler": "^1.12.2"
}
}
- CLI command:
yarn run parcel build src/index.html
🤔 Expected Behavior
The build should complete with no errors or warnings
😯 Current Behavior
The build completes, but it emits the following warning:
With `useBuiltIns` option, required direct setting of `corejs` option
💁 Possible Solution
This warning appears to come from @babel/preset-env. It seems like it might be possible to avoid by specifying corejs appropriately in transforms/babel.js
🔦 Context
I’m trying to bootstrap a project which requires no extra configuration than what Parcel comes with out of the box. It would be helpful for this warning to be resolved without having to add extra non-functional Babel configuration (several attempts at configuring correctly have failed).
💻 Code Sample
The following files with the addition of the above configuration should be enough to reproduce the issue.
src/index.html:
<!DOCTYPE html>
<html>
<body>
<div id="root">test</div>
<script src="./index.js"></script>
</body>
</html>
src/index.js:
document.getElementById('root').append('more test')
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.12.2 |
| Node | 11.9.0 |
| npm/Yarn | 1.13.0 |
| Operating System | macOS 10.14.3 |
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 28
- Comments: 46 (12 by maintainers)
Commits related to this issue
- Update package.json (@babel/core@7.4.0 issue) please check these resources below on the reasoning behind this problematic babel bug: - https://stackoverflow.com/questions/55251983/what-does-this-e... — committed to oakromulo/vue-cli by oakromulo 5 years ago
- bug #545 Set useBuiltIns to false by default and allow to set core-js version (Lyrkan) This PR was merged into the master branch. Discussion ---------- Set useBuiltIns to false by default and allow... — committed to symfony/webpack-encore by weaverryan 5 years ago
- Pin parcel to 1.12.3 Several warnings are emitted during build due to https://github.com/parcel-bundler/parcel/issues/2819 so pin parcel to a version without the issues. — committed to coocos/toy-tracer by coocos 5 years ago
Ok, let me explain the current situation:
@babel/preset-envgenerates imports tocore-js. Let’s assume that it only generates imports tocore-js@2, that it doesn’t know aboutcore-js@3. We can make this assumption becausecore-js@2is the default behavior.The fact that it generates those imports means that users need to have
"core-js": "^2.0.0"in theirpackage.json’s dependencies. Since almost every node project which usesnpmalready hascore-jsas a dependency of a dependency (it has three times the downlaods of react or of webpack), andnpmhoist packages to the top when possible, sonode_modules/core-jsalways existed even if it wasn’t defined as a dependency: even if it was documented, people didn’t notice that they where depending on a package which they hadn’t specified.Yesterday
core-js@3was released. If any package in your dependency tree (for example, as you noted in https://github.com/parcel-bundler/parcel/issues/2819#issuecomment-474982867, Babel), your app will have bothcore-js@2andcore-js@3in your dependencies three andnpmcan choose which to hoist. If it decides to hoistcore-js@3, all the imports pointing tocore-js@2will be broken. It is a major version of the package, so it isn’t unexpected that it breaks something. For this reason, users must havecore-js@2in their dependencies: if they are relying on a package, it needs to be explicit or major updates will be done when any of the dependencies updates its subdependency.Even if the necessity to
npm install --save core-jshas been documented since Babel 6, users didn’t do it. We needed to do something to make them aware about it, so we asked them not to rely on the default behavior but to be explicit about it:corejs: 2is a way of saying “I know I’m using core-js@2”. I know, the warning message doesn’t explain it and we will soon update it (https://github.com/babel/babel/pull/9716).An example of a project which relied on
core-jswithout it being installed isangular-cli: https://github.com/angular/angular-cli/issues/13954#issuecomment-474827906Relying on npm hoisting won’t work anymore, and we need to make people aware of the presence of
core-jsin their project.I don’t know if
parceldoes analysenode_modules, but if it does the only way to proper fix this issue is to set thecorejsoption you pass to preset env based on what will be bundled:corejs: require("core-js/package.json").version.Thanks for reporting the other issue, I’m looking at it.
I downgraded all babel packages to < 7.4 in https://github.com/parcel-bundler/parcel/commit/53c09b3cfa3a14bc0dc9875950b31e43d4a9a2e4 while we get this figured out. Published parcel v1.12.3.
See this stackoverflow question for some solutions/approaches.
Confirmed that this issue is solved with 1.12.3 of parcel
I only installed version 3.0.0 of “core-js”.(npm i -g core-js) No “core-js@2”!!!
My version of “core-js” in “package.json”: “core-js”: “^3.0.0” , “core-js-compat”: “^3.0.0” , “core-js-pure”: “^3.0.0”
and, My Babel configuration has the following information: ‘@babel/preset-env’, { targets: { browsers: [ ‘>= 10%’, ‘cover 95%’, ‘since 2017-01-01’, ‘iOS >= 10’, ‘Safari >= 10’, ‘Edge >= 16’, ‘Opera >= 47’, ‘Android >= 56’, ‘Chrome >= 56’, ‘ChromeAndroid >= 56’, ‘Firefox ESR’, ‘Firefox >= 54’, ‘FirefoxAndroid >= 54’, ‘last 2 Baidu major versions’, ‘last 2 OperaMini major versions’, ‘last 2 QQAndroid major versions’, ‘last 2 UCAndroid major versions’, ‘last 2 OperaMobile major versions’, ‘last 2 Samsung major versions’, ‘last 2 BlackBerry major versions’, ‘last 2 major versions’, ‘last 2 versions’, ‘not ie <= 11’, ‘not ie_mob <= 11’, ‘not dead’ ], safari: ‘tp’, esmodules: false }, modules: false, spec: false, loose: true, shippedProposals: true, useBuiltIns: ‘usage’ } ‘@babel/plugin-transform-runtime’, { helpers: true, regenerator: true, useESModules: true }
When the @babel/preset-env and @babel/plugin-transform-runtime options are set the “corejs” option, the value is: corejs: { version: 3, proposals: true } Report wrong!!! The error message is as follows:
1.txt
If only the “corejs” option of “@babel/plugin-transform-runtime” is set, and the value is: corejs: { version: 3, proposals: true } And there is no “corejs” option for “@babel/preset-env”!!! However, the value of the “useBuiltIns” option of “@babel/preset-env” is “usage”. It will go wrong.!!! The error message is as follows:
只启用transform.txt
But if me just set the “corejs” option of “@babel/preset-env”, the value is: corejs: { version: 3, proposals: true } No “corejs” option is set for “@babel/plugin-transform-runtime”! Then my project will compile successfully!!!
Also, 53c09b3 will only work until some other dependency will depend on
core-js@3. As you can see in https://github.com/parcel-bundler/parcel/issues/2819#issuecomment-474898805, it’s not a problem specific of v7.4.Sorry, just realized that 1.12.3 only rolled back the version of babel. I think I should keep this open until there is a definitive solution.
I just use these. you can also try update parcel,it maybe deal this bug
https://github.com/babel/babel/issues/9720
I believe that is probably a separate issue with babel 7.4, unrelated to the warning.
(btw this overriding behavior is bad and it’s going away in parcel 2, but it’s what we have right now)
Did you try to
npm install --save core-js@2?“
useBuiltInsnow requires direct setting ofcorejsversion option, without it will be used2by default and shown deprecation warning.” merged 3 hours ago at the time of writing.Didn’t realize the change was so recent. Looks like Babel is making a soft API change in 7.4.0. I doubt they’ll turn back on that, so unfortunately I think it has become a Parcel issue.