有半个月没用react了,今天在使用create-react-app创建项目时,当输入:
create-react-app train-ticket
控制台报了:
You are running `create-react-app` 5.0.0, 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 版本有关
然后自己检察了一下 npm 版本
npm -v
6.14.11
我的 npm 版本是 6.14.11
得到的解决办法是 :
当 npm 版本 >= 5.2 的时候,不能全局安装脚手架,需使用 npx create-react-app my-app 进行创建项目
当 npm 版本 < 5.2,则需全局安装脚手架,使用 create-react-app pro_name 进行项目创建
结果我按照上述方法,还是不行,报错一样
然后我就???再找!
最后还真找到解决了:
如果 npm>= 5.2 且使用 npx create-react-app my-app 依旧报错,可使用指令:
npx create-react-app@latest train-ticket
然后成功啦:
Created git commit.
Success! Created train-ticket at /Users/kongc/Desktop/train-ticket
Inside that directory, you can run several commands:
npm start
Starts the development server.
npm run build
Bundles the app into static files for production.
npm test
Starts the test runner.
npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!
We suggest that you begin by typing:
cd train-ticket
npm start
Happy hacking!