今天用create-react-app my-app,看到下面的提示:
A template was not provided. This is likely because you're using an outdated version of create-react-app.
Please note that global installs of create-react-app are no longer supported.
根據提示會看到是CRA(create-react-app)是過時的,且不再支持全局安裝CRA。
查了些資料可以用npx,用npx有兩種方法供參考:
1、你本地全局安裝過CRA,如果使用npx create-react-app myApp,它依然用的是本地安裝的過時的CRA,如果想使用遠程模塊,請使用
npx --ignore-existing create-react-app myApp
2、本地安裝的CRA已經沒有任何使用價值,可先卸載,再使用npx create-react-app myApp即可
- 卸載全局CRA
npm uninstall -g create-react-app
但是發現卸不掉CRA,因為下面的command還可以拿到它的版本號:
create-react-app -V
->3.0.1
怎么辦嘞?那就手動刪除吧,執行下面的command:
which create-react-app
->/usr/local/bin/create-react-app
rm -rf /usr/local/bin/create-react-app
create-react-app -V
-bash: /usr/local/bin/create-react-app: No such file or directory
刪除成功!
- 最后用npx就快速生成react項目,運行OK
npx create-react-app myApp