微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Create-react-app error : internal/modules/cjs/loader.js:311 ,当使用 npx 创建一个反应应用程序时

如何解决Create-react-app error : internal/modules/cjs/loader.js:311 ,当使用 npx 创建一个反应应用程序时

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

internal/modules/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

解决方法

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

同时验证节点安装是否正确,node -v && npm -v

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。