[英]create-react-app returns an Error: Cannot find module 'react-scripts/scripts/init.js' when executed
when I try to create a react project with both npm and yarn, it shows me the following error:当我尝试使用 npm 和 yarn 创建反应项目时,它显示以下错误:
I tried to reinstall node and make sure it was up to date, as well as create-react-app by running npm install -g create-react-app@latest.我尝试通过运行 npm install -g create-react-app@latest 重新安装 node 并确保它是最新的,以及 create-react-app。 I also removed the npm and npm-cache folders and the environment variable, but nothing works for me and I keep getting the same error.
我还删除了 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.
I think the problem arose from restoring my windows 10 to a previous state due to operating system problems, because before restoring it, when I run create-react-app it worked correctly.我认为问题是由于操作系统问题将我的 Windows 10 恢复到以前的状态,因为在恢复它之前,当我运行 create-react-app 时,它可以正常工作。
create-react-app --version 3.1.1 create-react-app --version 3.1.1
node -v v10.16.3节点 -v v10.16.3
npm -v 6.9.0 npm -v 6.9.0
SO Windows 10 Education SO Windows 10 教育版
Install a package.json with npm init
(press enter till is installed)使用
npm init
安装 package.json (按回车直到安装)
After that install react-scripts with npm i react-scripts
,之后使用
npm i react-scripts
安装npm i react-scripts
,
Then you can install react with npx create-react-app your-app
.然后你可以使用
npx create-react-app your-app
安装 react。
Change the directory to "your-app"将目录更改为“您的应用程序”
Run again npm i react-scripts
and it should work.再次
npm i react-scripts
,它应该可以工作。
Hope I did not missed a step, let me know if works :)希望我没有错过任何一步,如果有效,请告诉我:)
Just run this code on git bash:只需在 git bash 上运行此代码:
npm install
npm install react-scripts
npx create-react-app your-app-name
Maybe it will help somebody else.也许它会帮助别人。
This error can happen after you use create-react-app in case you have some invalid character in your path.如果您的路径中有一些无效字符,则在使用 create-react-app 后可能会发生此错误。
Remove charecteres like &
from your path.从您的路径中删除像
&
这样的字符。
For example, change from this:例如,从这里更改:
C:\Users\...\Documents\Section 3 Components & Start\my-app
To this:对此:
C:\Users\...\Documents\Section 3 Components Start\my-app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.