[英]Unable to start project after create-react-app: Error: Cannot find module 'C:\Users\pcname\Documents\react-scripts\bin\react-scripts.js'
[英]create-react-app returns an Error: Cannot find module 'react-scripts/scripts/init.js' when executed
当我尝试使用 npm 和 yarn 创建反应项目时,它显示以下错误:
我尝试通过运行 npm install -g create-react-app@latest 重新安装 node 并确保它是最新的,以及 create-react-app。 我还删除了 npm 和 npm-cache 文件夹和环境变量,但对我没有任何作用,而且我不断收到相同的错误。
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'react-scripts/scripts/init.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at [eval]:2:20
at Script.runInThisContext (vm.js:122:20)
at Object.runInThisContext (vm.js:329:38)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at evalScript (internal/bootstrap/node.js:589:27)
Aborting installation.
node has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting test/ from C:\Users\Esper\projects
Done.
我认为问题是由于操作系统问题将我的 Windows 10 恢复到以前的状态,因为在恢复它之前,当我运行 create-react-app 时,它可以正常工作。
create-react-app --version 3.1.1
节点 -v v10.16.3
npm -v 6.9.0
SO Windows 10 教育版
使用npm init
安装 package.json (按回车直到安装)
之后使用npm i react-scripts
安装npm i react-scripts
,
然后你可以使用npx create-react-app your-app
安装 react。
将目录更改为“您的应用程序”
再次npm i react-scripts
,它应该可以工作。
希望我没有错过任何一步,如果有效,请告诉我:)
只需在 git bash 上运行此代码:
npm install
npm install react-scripts
npx create-react-app your-app-name
也许它会帮助别人。
如果您的路径中有一些无效字符,则在使用 create-react-app 后可能会发生此错误。
从您的路径中删除像&
这样的字符。
例如,从这里更改:
C:\Users\...\Documents\Section 3 Components & Start\my-app
对此:
C:\Users\...\Documents\Section 3 Components Start\my-app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.