Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while loading config - You appear to be using a native ECMAScript module configuration file (Jest)

UPDATED.

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?

like image 836
tksilicon Avatar asked Apr 10 '20 18:04

tksilicon


2 Answers

SOLVED: For anyone who encounters this problem. 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.

like image 123
tksilicon Avatar answered Oct 08 '22 12:10

tksilicon


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"
  ]
}
like image 14
dhilt Avatar answered Oct 08 '22 12:10

dhilt