76

This error is coming up when I am making a pull request. There is a GitHub workflow audit that runs checks on the pull request and it loads the test file from another repository.

- name: Run Audits
      run: npx jest audits/ch-2 --json --outputFile=audits/ch-2.json --noStackTrace


Test suite failed to run

    /Users/frankukachukwu/StudioProjects/covid-19-estimator-tksilicon-js/babel.config.js: Error while loading config - You appear to be using a native ECMAScript module configuration file, which is only supported when running Babel asynchronously.

How do I solve this issue?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
tksilicon
  • 3,276
  • 3
  • 24
  • 36

2 Answers2

131

TL;DR: Changing babel.config.<extension> to babel.config.cjs did the work. Check babel docs if you need a different config.

This has got to do with Babel settings. The use of .mjs, cjs or .js extension for the babel.config.extension. In my case where I was running LTE Node 12.6.2. I needed this configuration at the root of my directory babel.config.cjs. cjs is what is applicable for Nodejs when using "type"="module". See more about it here on babel docs.

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current'
        }
      }
    ]
  ]
};

And jest.config.cjs at the root too.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
tksilicon
  • 3,276
  • 3
  • 24
  • 36
  • 105
    Renaming babel.config.js to babel.config.cjs did it for me! Thanks. – pbatey May 24 '20 at 21:27
  • @pbatey wow how do you explain that ?! Anyway thanks buddy saved me time. – Amesys Mar 31 '21 at 22:40
  • 3
    @Amesys I read that cjs means commonJS, I've been using node with --experimental-modules so I'm guessing .js defaults to modules (import) instead of commonJS (require). – pbatey Apr 20 '21 at 21:10
31

In addition to "cjs" solution, I was able to resolve this issue by converting babel.config.js to babel.config.json:

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "current"
        }
      }
    ],
    "@babel/preset-typescript"
  ]
}
dhilt
  • 18,707
  • 8
  • 70
  • 85