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

Env 7 / Node 4 useBuiltIns usage transpiling polyfill call with "import" not "require" #7457

Closed
reggi opened this issue Feb 28, 2018 · 8 comments · Fixed by #7562
Closed
Labels
claimed good first issue Has PR help wanted outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@reggi
Copy link

reggi commented Feb 28, 2018

Here's my config:

{
  "babel": {
    "presets": [
      [
        "@babel/preset-env",
        {
          "targets": {
            "node": "4.0.0"
          },
          "useBuiltIns": "usage",
          "debug": true,
          "shippedProposals": true
        }
      ]
    ]
  }
  "devDependencies": {
    "npm-run-all": "^4.1.2",
    "@babel/cli": "^7.0.0-beta.40",
    "@babel/core": "^7.0.0-beta.40",
    "@babel/preset-env": "^7.0.0-beta.40",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^22.4.1",
    "jest": "^22.4.2"
  }
}

Here's debug output:


@babel/preset-env: `DEBUG` option

Using targets:
{
  "node": "4"
}

Using modules transform: commonjs

Using plugins:
  transform-arrow-functions { "node":"4" }
  transform-block-scoping { "node":"4" }
@babel/preset-env: `DEBUG` option
  transform-classes { "node":"4" }
  transform-destructuring { "node":"4" }
  transform-for-of { "node":"4" }
  transform-function-name { "node":"4" }
  transform-object-super { "node":"4" }
  transform-parameters { "node":"4" }
  transform-spread { "node":"4" }
  transform-sticky-regex { "node":"4" }
  transform-unicode-regex { "node":"4" }
  transform-new-target { "node":"4" }
  transform-regenerator { "node":"4" }
  transform-exponentiation-operator { "node":"4" }
  transform-async-to-generator { "node":"4" }
  transform-dotall-regex { "node":"4" }
  proposal-async-generator-functions { "node":"4" }

Using targets:
  proposal-object-rest-spread { "node":"4" }
  proposal-optional-catch-binding { "node":"4" }
  proposal-unicode-property-regex { "node":"4" }

Using polyfills with `usage` option:
{
  "node": "4"
}

Using modules transform: commonjs

Using plugins:
  transform-arrow-functions { "node":"4" }
  transform-block-scoping { "node":"4" }
  transform-classes { "node":"4" }
  transform-destructuring { "node":"4" }
  transform-for-of { "node":"4" }
  transform-function-name { "node":"4" }
  transform-object-super { "node":"4" }
  transform-parameters { "node":"4" }
  transform-spread { "node":"4" }
  transform-sticky-regex { "node":"4" }
  transform-unicode-regex { "node":"4" }
  transform-new-target { "node":"4" }
  transform-regenerator { "node":"4" }
  transform-exponentiation-operator { "node":"4" }
  transform-async-to-generator { "node":"4" }
  transform-dotall-regex { "node":"4" }
  proposal-async-generator-functions { "node":"4" }
  proposal-object-rest-spread { "node":"4" }
  proposal-optional-catch-binding { "node":"4" }
  proposal-unicode-property-regex { "node":"4" }

Using polyfills with `usage` option:

[./functionality/bin/index.js] Based on your code and targets, none were added.

[./functionality/index.js] Added following polyfills:
  es7.array.includes { "node":"4" }
  regenerator-runtime { "node":"4" }
  es6.promise { "node":"4" }

Why on earth does my index.build.js file have an import statment?

./functionality/index.js

import "core-js/modules/es6.promise";

require("regenerator-runtime/runtime");

require("core-js/modules/es7.array.includes");
@babel-bot
Copy link
Collaborator

Hey @reggi! 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.

@mAAdhaTTah
Copy link
Contributor

mAAdhaTTah commented Mar 1, 2018

You need modules: "commonjs" in your config. See here.

Edit: Nevermind. That should be on by default. Do you have a repro case?

@loganfsmyth
Copy link
Member

Good call. preset-env should be using https://github.com/babel/babel/blob/master/packages/babel-helper-module-imports/README.md to handle this, and currently it is hardcoded to create import statements.

@Jessidhia
Copy link
Member

https://github.com/babel/babel/blob/007f8d19/packages/babel-preset-env/src/use-built-ins-plugin.js#L46 is the culprit. It's calling an ad-hoc createImport helper, which has a 3rd option to support require instead of import, but it's never given.

Maybe something that was added before preset-env got moved to the monorepo and thus got missed when the helper was introduced.

@loganfsmyth
Copy link
Member

Yeah I think that is likely the case. Should be a simple fix.

@debugpai
Copy link
Contributor

debugpai commented Mar 1, 2018

I would like to work on this

@existentialism
Copy link
Member

Maybe something that was added before preset-env got moved to the monorepo and thus got missed when the helper was introduced.

That is definitely the case :)

Ref: #6601 as well.

@loganfsmyth
Copy link
Member

@debugpai2 Go for it!

debugpai added a commit to debugpai/babel that referenced this issue Mar 2, 2018
debugpai added a commit to debugpai/babel that referenced this issue Mar 2, 2018
Swatto pushed a commit to Swatto/babel that referenced this issue Mar 9, 2018
Swatto pushed a commit to Swatto/babel that referenced this issue Mar 9, 2018
Swatto pushed a commit to Swatto/babel that referenced this issue Mar 9, 2018
Swatto added a commit to Swatto/babel that referenced this issue Mar 9, 2018
Swatto added a commit to Swatto/babel that referenced this issue Mar 9, 2018
aminmarashi pushed a commit to aminmarashi/babel that referenced this issue Mar 17, 2018
mAAdhaTTah added a commit to valtech-nyc/babel that referenced this issue Mar 18, 2018
* master: (131 commits)
  v7.0.0-beta.42
  Use strict namespace behavior for mjs files. (babel#7545)
  Remove outdated spec deviation note [skip ci] (babel#7571)
  Ensure that the backward-compat logic for plugin-utils copies over the version API properly. (babel#7580)
  Rename actual/expected test files to input/output (babel#7578)
  Use helper-module-import inside entry plugin too
  Use helper-module-imports instead of custom import (babel#7457)
  Fix "Module build failed: Error: Cannot find module '@babel/types'" (babel#7575)
  Wrap wrapNativeSuper helpers in redefining functions for better tree-shakeability (babel#7188)
  Favour extends helper over objectWithoutProperties when whole object gets copied anyway (babel#7390)
  Fix incorrect value of _cache in _wrapNativeSuper (babel#7570)
  [transform-classes] Fix typo in _wrapNativeSuper helper
  [typeof-symbol] Guard against undefined built-in globals
  update to beta.41 (babel#7568)
  v7.0.0-beta.41
  Fix import of type ConfigItem (babel#7561)
  Run node 9 on circleci and remove from travis (babel#7560)
  docs: [skip ci] fix proposal link text
  update preset-env after build-data (babel#7543)
  Re-add TEST_ONLY and use Jest's -t for TEST_GREP. (babel#7556)
  ...
mAAdhaTTah added a commit to valtech-nyc/babel that referenced this issue Mar 18, 2018
…ature/pipe-await

* 'master' of https://github.com/valtech-nyc/babel: (131 commits)
  v7.0.0-beta.42
  Use strict namespace behavior for mjs files. (babel#7545)
  Remove outdated spec deviation note [skip ci] (babel#7571)
  Ensure that the backward-compat logic for plugin-utils copies over the version API properly. (babel#7580)
  Rename actual/expected test files to input/output (babel#7578)
  Use helper-module-import inside entry plugin too
  Use helper-module-imports instead of custom import (babel#7457)
  Fix "Module build failed: Error: Cannot find module '@babel/types'" (babel#7575)
  Wrap wrapNativeSuper helpers in redefining functions for better tree-shakeability (babel#7188)
  Favour extends helper over objectWithoutProperties when whole object gets copied anyway (babel#7390)
  Fix incorrect value of _cache in _wrapNativeSuper (babel#7570)
  [transform-classes] Fix typo in _wrapNativeSuper helper
  [typeof-symbol] Guard against undefined built-in globals
  update to beta.41 (babel#7568)
  v7.0.0-beta.41
  Fix import of type ConfigItem (babel#7561)
  Run node 9 on circleci and remove from travis (babel#7560)
  docs: [skip ci] fix proposal link text
  update preset-env after build-data (babel#7543)
  Re-add TEST_ONLY and use Jest's -t for TEST_GREP. (babel#7556)
  ...
mAAdhaTTah added a commit to valtech-nyc/babel that referenced this issue Mar 21, 2018
* master: (140 commits)
  Update to beta.42 (babel#7609)
  Disable flow on transformClass, fix preset-env errors (babel#7605)
  Logical Assignment: ensure computed key isn't recomputed (babel#7604)
  Remove obsolete max-len eslint rule and reformat some stuff to fit (babel#7602)
  Centralize Babel's own compilation config to make it easier to follow. (babel#7599)
  Run prettier to format all JSON.
  Tweak es2015-related plugin order in preset-env (babel#7586)
  Refactored quirky inheritance in babel-plugin-transform-classes (babel#7444)
  Add RegExp support to include/exclude preset-env options (babel#7242)
  v7.0.0-beta.42
  Use strict namespace behavior for mjs files. (babel#7545)
  Remove outdated spec deviation note [skip ci] (babel#7571)
  Ensure that the backward-compat logic for plugin-utils copies over the version API properly. (babel#7580)
  Rename actual/expected test files to input/output (babel#7578)
  Use helper-module-import inside entry plugin too
  Use helper-module-imports instead of custom import (babel#7457)
  Fix "Module build failed: Error: Cannot find module '@babel/types'" (babel#7575)
  Wrap wrapNativeSuper helpers in redefining functions for better tree-shakeability (babel#7188)
  Favour extends helper over objectWithoutProperties when whole object gets copied anyway (babel#7390)
  Fix incorrect value of _cache in _wrapNativeSuper (babel#7570)
  ...
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 14, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
claimed good first issue Has PR help wanted outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
7 participants