React错误:子编译失败:必须使用import来加载ES模块



我已经在我的ubuntu系统上做了一个react项目,并上传到github上,现在我正在克隆我的windows系统上的相同的存储库,并执行npm install和npm start。显示如下错误:

查看这些图片[1]: https://i.stack.imgur.com/3cKFp.png[2]: https://i.stack.imgur.com/v5OHz.png

我有点新的反应,所以请帮助我解决这个问题。我的npm在windows的版本是8.7.0节点版本为v12.16.3

Compiled with problems:X 
ERROR
Must use import to load ES Module: C:UsersuserDesktopportfrontendnode_modules@eslinteslintrcuniversal.js
require() of ES modules is not supported.
require() of C:UsersuserDesktopportfrontendnode_modules@eslinteslintrcuniversal.js from C:UsersuserDesktopportfrontendnode_moduleseslintliblinterlinter.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename universal.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:UsersuserDesktopportfrontendnode_modules@eslinteslintrcpackage.json.

ERROR
Error: Child compilation failed:
Must use import to load ES Module: C:UsersuserDesktopportfrontendnode_modules@eslinteslintrcuniversal.js
require() of ES modules is not supported.
require() of C:UsersuserDesktopportfrontendnode_modules@eslinteslintrcuniversal.js from C:UsersuserDesktopportfrontendnode  _moduleseslintliblinterlinter.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module"   which defines all .js files in that package scope as ES modules.
Instead rename universal.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:UsersuserDesk  topportfrontendnode_modules@eslinteslintrcpackage.json.

- child-compiler.js:169 
[frontend]/[html-webpack-plugin]/lib/child-compiler.js:169:18

- Compiler.js:564 
[frontend]/[webpack]/lib/Compiler.js:564:11

- Compiler.js:1183 
[frontend]/[webpack]/lib/Compiler.js:1183:17


- Hook.js:18 Hook.CALL_ASYNC_DELEGATE [as _callAsync]
[frontend]/[tapable]/lib/Hook.js:18:14

- Compiler.js:1179 
[frontend]/[webpack]/lib/Compiler.js:1179:33

- Compilation.js:2784 finalCallback
[frontend]/[webpack]/lib/Compilation.js:2784:11

- Compilation.js:3089 
[frontend]/[webpack]/lib/Compilation.js:3089:11


- Hook.js:18 Hook.CALL_ASYNC_DELEGATE [as _callAsync]
[frontend]/[tapable]/lib/Hook.js:18:14

看来您的节点版本有问题。react组件的大部分将运行在版本16的节点上。升级你的节点版本,我想它会解决你的问题。

答案就在错误本身。你正在使用require在你的通用js中,这是不支持的,请使用import代替

相关内容

  • 没有找到相关文章

最新更新