app 升级至3.3.1版本踩坑记

app 升级至3.3.1版本踩坑记


电脑原先使用npm install -g create-react-app命令全局安装过,根据文档先全局卸载npm uninstall -g create-react-app,然后采用npx create-react-app my-app创建项目。然而,项目创建完后,却只生成了node_modules,package.json,package_lock.json或yarn.lock这几个文件夹,同时报错:

app 升级至3.3.1版本踩坑记

解决

1、运行create-react-app -V查看版本号,发现还可以拿到版本号,说明未被完全删除。
2、运行where create-react-app命令,若是有返回内容,则将返回内容全部手动删除。在我的电脑上操作,返回了以下两个文件路径。

C:\Users\XXXX\AppData\Local\Yarn\config\global\node_modules\.bin\create- react-app C:\Users\XXXXX\AppData\Local\Yarn\config\global\node_modules\.bin\create- react-app.cmd

3、再次运行create-react-app -V查看版本号,可看到


4、运行npx create-react-app my-app命令。

问题

若是运行npx create-react-app my-app命令,出现

npm ERR! code ENOLOCAL npm ERR! Could not install from "Files\nodejs\node_cache\_npx\18944" as it does not contain a package.json file.

根据


是因为安装node的路径中存在空格。我的node是安装在E:\Program Files\nodejs,它并不识别Program Files中的空格。

解决方法:

cmd开启dos窗口,运行

npm config set prefix "E:\Program~1\nodejs\node_global" npm config set cache "E:\Program~1\nodejs\node_cache"

参考自:
Template not provided using create-react-app
windows中node环境采坑

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/8ee298ce786f9704ab877657e4eaf816.html