记录一次 create-react-app 构建项目失败

有半个月没用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!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值