【问题标题】:Create-react-app error : internal/modules/cjs/loader.js:311 , when using npx to create a react app创建反应应用程序错误:internal/modules/cjs/loader.js:311,当使用 npx 创建反应应用程序时
【发布时间】:2021-07-22 10:38:34
【问题描述】:

当使用 npx create-react-app 创建一个新的 react 项目时,进程停止并出现错误:internal/modules/cjs/loader.js:311。

内部/模块/cjs/loader.js:311 抛出错误; ^ 错误:找不到模块“C:\Users\shonm\Desktop\Web Development\WebSites\test1\node_modules\fs-extra\lib\index.js”。请验证 package.json 是否具有有效的“main” 进入

 PS C:\Users\shonm\Desktop\Web Development\WebSites> npx create-react-app test1

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

yarn add v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.13: The platform "win32" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.3.2: The platform "win32" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
.......
Done in 30.17s.
**internal/modules/cjs/loader.js:311
      throw err;
      ^
Error: Cannot find module 'C:\Users\shonm\Desktop\Web Development\WebSites\test1\node_modules\fs-extra\lib\index.js'. Please verify that the package.json has a valid "main" 
entry**
    at tryPackage (internal/modules/cjs/loader.js:303:19)
  
  requestPath: 'fs-extra'
}

Aborting installation.
  node  has failed.

Deleting generated file... node_modules

【问题讨论】:

    标签: node.js reactjs npm create-react-app yarnpkg


    【解决方案1】:

    当全局安装了 npm 和 yarn 时会发生这种情况。 create-react-app 使用 yarn 来构建。要解决此问题,请使用 npx create-react-app projectname --use-npm,或从全局包中删除 yarn。

    同时使用 node -v && npm -v

    验证节点安装是否正确

    【讨论】:

    • ^^ 这是上述问题的解决方案
    猜你喜欢
    • 1970-01-01
    • 2022-07-11
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 2021-08-16
    • 2016-08-08
    相关资源
    最近更新 更多