简体   繁体   English

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

[英]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.0node版本是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.

相关问题 Gulp 抛出错误“必须使用导入来加载 ES 模块” - Gulp throws error 'Must use import to load ES Module' ESLint - 错误:必须使用导入来加载 ES 模块 - ESLint - Error: Must use import to load ES Module 节点错误必须使用import来加载ES模块 - Node Error Must use import to load ES module 错误:必须使用导入来加载 ES 模块 - 使用 Typescript 和 Node - Error: Must use import to load ES Module - Using Typescript and Node ElectronJS:必须使用导入来加载 ES 模块 - ElectronJS: Must use import to load ES Module SSR with Node, Webpack, React, Express, Material UI, React Router - 错误 [ERR_REQUIRE_ESM]: 必须使用导入加载 ES 模块 - SSR with Node, Webpack, React, Express, Material UI, React Router - Error [ERR_REQUIRE_ESM]: Must use import to load ES Module 错误:必须使用 import 加载 ES 模块:不支持 ES 模块的 D:\\node_modules\\react-markdown\\index.js require() - Error: Must use import to load ES Module: D:\node_modules\react-markdown\index.js require() of ES modules is not supported 更新 angular 时必须使用 import 加载 ES Module - Must use import to load ES Module while updating angular 必须使用import加载ES Module.eslintrc.js - Must use import to load ES Module .eslintrc.js Vue-konva 运行出错:必须使用导入来加载 ES 模块 - Vue-konva running into error: Must use import to load ES Module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM