react:创建新项目

React中文官方文档给出创建新应用的最佳方式(命令行)。

npx create-react-app my-app
cd my-app
npm start

终端直接报错,提示如下:

bogon:~ jing$ npx creat-react-app myJob_react
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.com/creat-react-app - Not found
npm ERR! 404 
npm ERR! 404  'creat-react-app@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jing/.npm/_logs/2020-08-25T08_15_11_792Z-debug.log
安装 [ 'creat-react-app@latest' ] 失败,错误代码:1

根据提示应该是没有全局安装creat-react-app这个脚手架工具造成的,因此我们需要先安装creat-react-app这个脚手架工具造成,安装命令提示入下:

npm install -g create-react-app

但是,我本地这样也给我报错了,也是醉了。

npm ERR! code E503
npm ERR! 503 Service Temporarily Unavailable - GET https://cdn.npm.taobao.org/create-react-app/-/create-react-app-3.4.1.tgz
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jing/.npm/_logs/2020-08-25T08_33_29_956Z-debug.log

研究了半天是npm 淘宝镜像的问题,换了几次镜像也没有安装成功,决定换个方式安装。使用 cnpm,使用之前先确认下是否安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org

cnpm -v
cnpm install -g create-react-app
cd my-app
npm start

中间还有很多曲折,在自己查看报错信息后一一对应安装,改正,总算开启了第一个react项目。

猜你喜欢

转载自blog.csdn.net/Cituses/article/details/108226009