How to fix 'Error: Module name "xxxxx" has not been loaded yet for context: _. Use require([])' when using amd module transforms with CoreJS

Viewed 329

I'm trying to add CoreJS to a project for using as a polyfill. In the core js file, I have:

import 'core-js/stable';
import 'regenerator-runtime/runtime';

My babel config is:

{
    presets   : [
        [
            '@babel/env',
            {
                'useBuiltIns': 'entry',
                'corejs'     : 3,
                'modules'    : 'amd'
            }
        ]
    ]
}

When the file compiles, the output js looks like:

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

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

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

...

The browser console errors out with:

Error: Module name "../es" has not been loaded yet for context: _. Use require([])
https://requirejs.org/docs/errors.html#notloaded

Changing the require statements to use arrays like RequireJS is used to solves the issue with that file, but continues to occur within core-js.

Example fix:

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

I'm assuming there's an issue with Babel's AMD transformer, or maybe there's another solution to this.

0 Answers
Related