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

[@babel/preset-env] Provides broken warnings on compile with useBuiltIns #9751

Closed
bradennapier opened this issue Mar 22, 2019 · 10 comments
Closed
Labels
i: invalid outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@bradennapier
Copy link

bradennapier commented Mar 22, 2019

Bug Report

Current Behavior

WARNING: We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

  npm install --save core-js@2    npm install --save core-js@3
  yarn add core-js@2              yarn add core-js@3

When using useBuiltIns it is giving this warning. So I changed and used core-js 3.0.0 since it seemed like that was an option based on it saying i could run that.

I added corejs to the config stating 3.0.0, but then it just errors and no longer works:

Error: Cannot find module 'core-js/modules/es7.symbol.async-iterator'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/Shared/Development/projects/idex-server-v2/node_modules/@auroradao/logger/dist/constants.js:9:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Module._compile (/Users/Shared/Development/projects/idex-server-v2/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Object.newLoader [as .js] (/Users/Shared/Development/projects/idex-server-v2/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:599:32)

Note that installing and using corejs 2 does work - so this is just reporting about the fact its confusing it seems to indicate support of 3.0.0 when it doesnt have it

Expected behavior/code

be more clear that i should not use core-js@3 if it is not supported / remove that entire set of yarn commands to not confuse people.

Babel Configuration (.babelrc, package.json, cli command)

module.exports = function getBabelConfiguration(api) {
  api.cache.never();
  return {
    presets: [
      [
        '@babel/preset-env',
        {
          useBuiltIns: 'usage',
          corejs: '3.0.0',
          shippedProposals: true,
          targets: {
            node: '10.15',
          },
        },
      ],
    ],
    plugins: [
      [
        'module-resolver',
        {
          root: ['./src/shared'],
        },
      ],
      '@babel/plugin-transform-flow-strip-types',
      '@babel/proposal-class-properties',
      '@babel/proposal-optional-chaining',
      'dynamic-import-node',
      'lodash',
    ],
  };
};

Environment

  • Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34] See below
  • Node/npm version: [e.g. Node 8/npm 5] Node 10.15
  • OS: [e.g. OSX 10.13.4, Windows 10] OSX
  • Monorepo: [e.g. yes/no/Lerna] no
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.4.0",
    "@babel/node": "^7.2.2",
    "@babel/plugin-proposal-class-properties": "^7.4.0",
    "@babel/plugin-proposal-optional-chaining": "^7.2.0",
    "@babel/preset-env": "^7.4.2",
    "@babel/preset-flow": "^7.0.0",
@babel-bot
Copy link
Collaborator

Hey @bradennapier! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Mar 22, 2019

It's probably a bug with one of your dependencies (you can find it in the stack trace), which is importing core-js (and it is relying on core-js@2) without specifying it in their dependencies.


EDIT: It is a bug with the @auroradao/logger package (though I can't confirm it because I couldn't find it on npm): on line 9 of @auroradao/logger/dist/constants.js this library is requireing core-js/modules/es7.symbol.async-iterator (which only existed in core-js@2), but I bet that @auroradao/logger/package.json doesn't contain core-js@2 in the "dependencies" section.

@bradennapier
Copy link
Author

Sweet, thanks! Makes sense and yeah that is a private package. Thanks!

@bradennapier
Copy link
Author

Note to anyone doing this - I had to delete my node_modules when changing to core-js 3 or i got the following errors:

TypeError: [BABEL] /Users/Shared/Development/projects/task-handler/src/constants.js: (0 , _semver(...).coerce) is not a function

Guessing it is a cache issue, not quite sure.

@nicolo-ribaudo
Copy link
Member

Yeah, that is our fault 😛 It's fixed on master and it will be in the next release. In the meantime, as you mentioned, reinstalling node_modules should be enough.

@bradennapier
Copy link
Author

bradennapier commented Mar 26, 2019

Thanks, easy enough to fix :) . Appreciate all you guys do!

@mnpenner
Copy link

corejs option is not documented here

@jnwng
Copy link

jnwng commented Mar 28, 2019

corejs option is not documented here

concretely, the set of options sent to @babel/preset-env needs to have this property like so:

{
  "presets": [
    "@babel/preset-flow",
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "8.10"
        },
        "corejs": "2", // <---
        "useBuiltIns": "usage"
      }
    ]
  ]
}

along with the dependency in package.json

@manigandham
Copy link

core-js@3 is a big new release with tighter integration into babel, worth reading the blog post: https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md

Since @babel/preset-env now supports core-js@2 and core-js@3, useBuiltIns requires setting a new option, corejs, which specifies the used version (corejs: 2 or corejs: 3). If it isn't directly set, corejs: 2 will be used by default and it will show a warning.

@crayner
Copy link

crayner commented Apr 8, 2019

Came here looking for help on this one for Symfony Webpack throwing this warning. In Symfony webpack.config.js add the following:

    .configureBabel((babelConfig) => {
        const preset = babelConfig.presets.find(([name]) => name === "@babel/preset-env");
        if (preset !== undefined) {
            preset[1].useBuiltIns = "usage";
            preset[1].corejs = '3.0.0';
        }
    })

This appears to have removed the warning.

Eric-Guo added a commit to thape-cn/oauth2id that referenced this issue May 26, 2019
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 9, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jul 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: invalid outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

8 participants