简体   繁体   English

在 ASP.NET 样板文件 ZC6E190B284635 不能在 reactjs 的一部分中运行 npm 测试时,会出现错误:09 无法在外部使用 import333C48EZ 模块

[英]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.

相关问题 当我尝试在我的 React 应用程序中运行 npm 测试时出现错误“SyntaxError: Cannot use import statement outside a module” - The error "SyntaxError: Cannot use import statement outside a module" appears when I try to run npm test in my react application SyntaxError:不能在模块外使用 import 语句,如何使用 react-native-svg 为 Web 运行测试单元? - SyntaxError: Cannot use import statement outside a module, how to run test unit with react-native-svg for the Web? ASP.NET - 未捕获的语法错误:无法在模块外使用导入语句 - ASP.NET - Uncaught SyntaxError: Cannot use import statement outside a module “未捕获的语法错误:无法在模块外使用导入语句”导入时 ReactJS - "Uncaught SyntaxError: Cannot use import statement outside a module" When Importing ReactJS &#39;SyntaxError: 不能在模块外使用 import 语句&#39; - 'SyntaxError: Cannot use import statement outside a module' SyntaxError: 不能在模块外使用 import 语句 - SyntaxError: Cannot use import statement outside a module 未捕获的语法错误:无法在使用 reactjs CDN 链接的模块外部使用导入语句 - Uncaught SyntaxError: Cannot use import statement outside a module using reactjs CDN Links SyntaxError: 无法在动态导入 Nextjs 的模块外使用 import 语句 - SyntaxError: Cannot use import statement outside a module with dynamic import of Nextjs 当我想在本地服务器上运行我的代码时,我总是会收到这种错误“SyntaxError: Cannot use import statement outside a module” - When I wants to run my code in local server i always get this kinds of error “SyntaxError: Cannot use import statement outside a module” 导入 React = &#39;SyntaxError: 不能在模块外使用导入语句&#39; - Importing React = 'SyntaxError: Cannot use import statement outside a module'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM