1. 程式人生 > 程式設計 >windows下create-react-app 升級至3.3.1版本踩坑記

windows下create-react-app 升級至3.3.1版本踩坑記

windows下create-react-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.jsonyarn.lock這幾個資料夾,同時報錯:

windows下create-react-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檢視版本號,可看到

windows下create-react-app 升級至3.3.1版本踩坑記

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.

根據

windows下create-react-app 升級至3.3.1版本踩坑記

是因為安裝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環境採坑

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。