Upgrading Node JS and ERR_REQUIRE_ESM: Must use import to load ES Module: 'inheritsloose.js' of Babel Runtime

Viewed 6007

The following error is emitted in my Node JS/React JS application after upgrading Node JS to v.12. I'm currently using @babel/core 7.10.1. How should this error be resolved?

Log of error emitted from Babel

Here is my babel.config.js:

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
    '@babel/preset-react',
    '@babel/preset-typescript',
  ],
  plugins: [
    '@babel/plugin-proposal-class-properties',
    ['@babel/plugin-proposal-decorators', { legacy: true }],
    '@babel/plugin-proposal-export-default-from',
    '@babel/plugin-proposal-export-namespace-from',
    '@babel/plugin-syntax-dynamic-import',
    '@babel/plugin-transform-react-constant-elements',
    '@babel/plugin-transform-react-inline-elements',
  ],
  ignore: ['node_modules', 'build'],
};
2 Answers

I had nested package.json files within my application. These package.json files defined dependencies. I believe that parts of the app were being transpiled with different versions of Babel. I flattened my application and removed the nested package.json files. This action solved my problem.

Related