如何避免在升级Windows下create-react-app至3.3.1版本时遇到各种坑?

2026-04-05 11:139阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计543个文字,预计阅读时间需要3分钟。

如何避免在升级Windows下create-react-app至3.3.1版本时遇到各种坑?

使用电脑前,先全局安装`create-react-app`。输入命令`npm install -g create-react-app`。接着,根据文档卸载全局版本,使用`npm uninstall -g create-react-app`。然后,创建新项目:`npx create-react-app my-app`。项目创建成功后,会生成相关文件。


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

解决

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环境采坑

如何避免在升级Windows下create-react-app至3.3.1版本时遇到各种坑?

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

本文共计543个文字,预计阅读时间需要3分钟。

如何避免在升级Windows下create-react-app至3.3.1版本时遇到各种坑?

使用电脑前,先全局安装`create-react-app`。输入命令`npm install -g create-react-app`。接着,根据文档卸载全局版本,使用`npm uninstall -g create-react-app`。然后,创建新项目:`npx create-react-app my-app`。项目创建成功后,会生成相关文件。


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

解决

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环境采坑

如何避免在升级Windows下create-react-app至3.3.1版本时遇到各种坑?

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。