Babel Polyfills with PresetEnv

Since Aurelia only really does the bare minimum polyfilling to get Aurelia running, I’d like to get @babel/preset-env working. I keep running into core-js module issues that don’t make sense:

require.js:168 Uncaught Error: Module name "core-js/modules/es.array.reverse" has not been loaded yet for context: _. Use require([])
https://requirejs.org/docs/errors.html#notloaded
    at makeError (require.js:168:1)
    at Object.localRequire [as require] (require.js:1436:1)
    at requirejs (require.js:1797:1)
    at users.html:1:1

The define call is in the vendor-bundle.js, but somehow it’s not available to the app-bundle in time for it’s ‘require’ call.

babel.config.json :

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "loose": true,
        "exclude": [
          "@babel/plugin-proposal-dynamic-import"
        ],
        "useBuiltIns": "usage",
        "corejs": "3.26.1",
        "debug": true
      }
    ]
  ],
  "plugins": [
    [
      "@babel/plugin-proposal-decorators",
      {
        "legacy": true
      }
    ],
    [
      "@babel/plugin-proposal-class-properties",
      {
        "loose": true
      }
    ],
    "@babel/plugin-syntax-dynamic-import"
  ]
}

Appears to be an open issue with Babel: AMD modules with useBuiltIns not correctly implemented · Issue #10333 · babel/babel · GitHub

Anyone here found a good workaround? I’m about to give transform-amd-to-commonjs a try

Hmmm okay, it’s a little deeper than Babel. They depend heavily on core-js and it does not transpile from cjs to any other format without major breakage. So… I’ll be taking the whole project away from requirejs so I don’t have to prepend/import the whole core-js library anymore. Fingers crossed the webpack migration will go well…

1 Like

I probably would never need this but thanks for documenting your journey on this for others that might.

1 Like