Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 加载配置时出错-您似乎正在使用本机ECMAScript模块配置文件(Jest)_Node.js_Express_Jestjs_Babeljs_Babel Jest - Fatal编程技术网

Node.js 加载配置时出错-您似乎正在使用本机ECMAScript模块配置文件(Jest)

Node.js 加载配置时出错-您似乎正在使用本机ECMAScript模块配置文件(Jest),node.js,express,jestjs,babeljs,babel-jest,Node.js,Express,Jestjs,Babeljs,Babel Jest,更新 当我发出拉取请求时,会出现此错误。有一个github工作流审计,它对pull请求运行检查,并从另一个存储库加载测试文件 - 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-estima

更新

当我发出拉取请求时,会出现此错误。有一个github工作流审计,它对pull请求运行检查,并从另一个存储库加载测试文件

- 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.

如何解决此问题?

已解决:适用于遇到此问题的任何人。这与巴别塔的设置有关。在babel.config.extension中使用.mjs、cjs或js扩展名。在我运行LTE节点12.6.2的情况下。我需要在目录babel.config.cjs的根目录下进行此配置。cjs是在使用“类型”=“模块”时适用于NodeJ的


还有根目录下的jest.config.cjs。

你没有一个
jest.config.js
?对于nodejs,我更惊讶的是你需要babel.config。朱利安,我该怎么办?你是使用
导入
还是
需要
?@Gaz_-Edge修复了。将babel.config.js重命名为babel.config.cjs为我做到了这一点!谢谢。@pbatey哇,你怎么解释?!无论如何,感谢buddy为我节省了时间。@Amesys我读到cjs表示commonJS,我一直在使用node with--experimental modules,所以我猜。js默认为modules(import)而不是commonJS(require)。
module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current'
        }
      }
    ]
  ]
};