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

AMD modules with useBuiltIns not correctly implemented #10333

Open
roti opened this issue Aug 13, 2019 · 1 comment

Comments

@roti
Copy link

commented Aug 13, 2019

Bug Report

Current Behavior
I am using Babel with babel-preset-react and babel-preset-env in an environment where modules are managed by requirejs.

Everything is latest version. The generated .js files include code like this (in the top level of the .js file):

require("core-js/modules/es.symbol");

require("core-js/modules/es.symbol.description");

require("core-js/modules/es.symbol.iterator");

require("core-js/modules/es.array.find");

require("core-js/modules/es.array.iterator");

require("core-js/modules/es.array.map");

require("core-js/modules/es.function.name");

require("core-js/modules/es.object.assign");

require("core-js/modules/es.object.get-own-property-descriptor");

require("core-js/modules/es.object.get-prototype-of");

require("core-js/modules/es.object.to-string");

require("core-js/modules/es.string.iterator");

require("core-js/modules/es.string.match");

require("core-js/modules/web.dom-collections.iterator");

This applies to configurations with core-js@2 and babel-transform-runtime as well.

Expected behavior/code
I expect AMD modules to be compatible with requirejs, which in this case means that modules are not loaded with the code above. The following code will fail with the error Module name ... has not been loaded yet for context

require("core-js/modules/es.string.match");

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

{
  "presets": [["@babel/preset-env", {
  "targets": {"ie": 11, "chrome": "58", "firefox": "50"},
    "modules": "amd",
    "useBuiltIns": "usage",
    "corejs": 3,
    "ignoreBrowserslistConfig": true}],
    "@babel/preset-react"],
  "plugins": ["@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-object-rest-spread"],
  "sourceMaps": "inline"
}

Environment

  • Babel version(s): 7.5.5
  • Node/npm version: Node v8.9.4/npm v6.10.3
  • OS: Windows 10
  • How you are using Babel: through a sbt plubin, but I'm pretty sure that it has no relation to the problem at hand

Possible Solution
Include these dependencies in the module definition as normal dependencies (i.e. when calling define) like this:

define(["exports", "core-js/modules/es.symbol", "core-js/modules/es.symbol.description"], function ...);

or use the simplified define wrapper as defined by the requirejs documentation, though I'm not 100% sure this is the right solution.

The main issue here is that with AMD modules require is asynchronous so code like below does not work as expected.

var mymodule = require("mymodule");
require("mymodule");
@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Aug 13, 2019

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

JLHwung added a commit to JLHwung/babel that referenced this issue Aug 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.