[英]React Error: Child compilation failed: Must use import to load ES Module
I have done a react project on my ubuntu system and uploaded on github, now I am cloning that same repository on my windows system and doing npm install and npm start.我已经在我的 ubuntu 系统上完成了一个反应项目并上传到 github,现在我正在我的 windows 系统上克隆相同的存储库并执行 npm 安装和 npm 启动。 It is showing this errors.
它显示此错误。
Check these images [1]: https://i.stack.imgur.com/3cKFp.png [2]: https://i.stack.imgur.com/v5OHz.png检查这些图像[1]: https://i.stack.imgur.com/3cKFp.png [2]: https://i.stack.imgur.com/v5OHz.png
I am bit new to react so please help me to fix this issue.我对反应有点陌生,所以请帮我解决这个问题。 My npm version on windows is 8.7.0 and node version is v12.16.3
我在windows上的npm版本是8.7.0 , node版本是v12.16.3
Compiled with problems:X
ERROR
Must use import to load ES Module: C:\Users\user\Desktop\port\frontend\node_modules\@eslint\eslintrc\universal.js
require() of ES modules is not supported.
require() of C:\Users\user\Desktop\port\frontend\node_modules\@eslint\eslintrc\universal.js from C:\Users\user\Desktop\port\frontend\node_modules\eslint\lib\linter\linter.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:\Users\user\Desktop\port\frontend\node_modules\@eslint\eslintrc\package.json.
ERROR
Error: Child compilation failed:
Must use import to load ES Module: C:\Users\user\Desktop\port\frontend\node_modules\@eslint\eslintrc\universal.js
require() of ES modules is not supported.
require() of C:\Users\user\Desktop\port\frontend\node_modules\@eslint\eslintrc\universal.js from C:\Users\user\Desktop\port\frontend\node _modules\eslint\lib\linter\linter.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:\Users\user\Desk top\port\frontend\node_modules\@eslint\eslintrc\package.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
It seems that you have a problem with your node version.看来您的节点版本有问题。 Most of the react component to run on node version 16. Upgrade your node version and I think it will solve your issue.
大多数反应组件在节点版本 16 上运行。升级您的节点版本,我认为它会解决您的问题。
The answer is in the error itself.答案在于错误本身。 You are using require in your universal js which is not supported, please use import instead
您在不支持的通用 js 中使用 require,请改用 import
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.