[英]When run npm test in reactjs part of ASP.NET Boilerplate Web Application SyntaxError: Cannot use import statement outside a module
I'm use ASP.NET Boilerplate Web Application for my project when i want to run the default test for frontend of project with npm test facing this error:当我想使用 npm 测试运行项目前端的默认测试时,我正在为我的项目使用 ASP.NET Boilerplate Web Application
FAIL src/App.test.tsx
● Test suite failed to run
D:\Taratech\safe\reactjs\node_modules\antd\es\spin\style\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import '../../style/index.less';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at new Script (node:vm:100:7)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
at Object.<anonymous> (src/components/Loading/index.tsx:12:1)
at Object.<anonymous> (src/components/Loadable/index.tsx:2:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 10.975s
Ran all test suites.
Watch Usage: Press w to show more.
then when i add "type": "module",
to package.json facing this error:然后当我添加"type": "module",
package.json 面临这个错误:
D:\Taratech\safe\reactjs\node_modules\@craco\craco\lib\config.js:46
const config = require(configFilePath);
^
craco\craco\lib\config.js not supported.
craco.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename craco.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in D:\Taratech\safe\reactjs\package.json to treat all .js files as CommonJS
(using .mjs for all ES modules instead).
at loadCracoConfig (D:\Taratech\safe\reactjs\node_modules\@craco\craco\lib\config.js:46:20)
at Object.<anonymous> (D:\Taratech\safe\reactjs\node_modules\@craco\craco\scripts\test.js:20:21) {
code: 'ERR_REQUIRE_ESM'
}
can any one help me?谁能帮我?
Dear often this caused by NodeJs Version, If you are using latest version of abp consider using the last version of NodeJs and Consider using yarn instead of npm亲爱的,这通常是由 NodeJs 版本引起的,如果您使用的是最新版本的 abp,请考虑使用最新版本的 NodeJs,并考虑使用 yarn 而不是 npm
Good luck祝你好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.