问题
晴朗湛蓝的高空万里无云,像碧玉一样澄澈。早早来到公司,想要创建一个新的 react 项目,于是打开电脑,照着文档在命令行敲入命令。。
npx create-react-app my-study-app
结果居然创建不成功,报了以下错误。。
You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.1).
We no longer support global installation of Create React App.
Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app
The latest instructions for creating a new app can be found here:
https://create-react-app.dev/docs/getting-started/
原因
看到控制台还提示解决方法,很开心,于是我照着敲
npm uninstall -g create-react-app
up to date, audited 1 package in 570ms
found 0 vulnerabilities
再来一遍,还是报上面的错误,我的心痛啊,一口老血吐在键盘上。
最后发现可能是 npm 缓存发神经,npm uninstall 没有正确删除 create-react-app
解决
有几种解决方法,我用第一种解决了,其他两种看着试试看吧。
- 第一种方法,命令行清除缓存
npx clear-npx-cache
- 第二种方法,手动清除 npm 缓存
苹果系统,执行下面命令
rm -rf ~/.npm/_npx
windows 系统,手动删除 %LocalAppData%/npm-cache/_npx
这个文件夹
最后用管理员权限执行
npm cache clean --force
- 第三种方法,执行下面命令看看。。强制使用指定的版本来执行
npx create-react-app@5.0.0 my-app --use-npm