运行命令

npm install -g create-react-app
create-react-app  first-demo

在SF上查到说是或许是因为国内npm拉去资源,拉去不到的问题,可以试着从解决创建create-react-app慢的方法着手:

解决方法:

/换源
npm config set registry https://registry.npm.taobao.org
//配置后通过以下方法验证是否成功
npm config get registry

再重新使用create-react-app  first-demo ,我这还是报错。。。

reating a new React app in /Users/xiaoxiao/Documents/MyReactDemo/first-demo.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

npm ERR! code EACCES
npm ERR! syscall open
npm ERR! path /Users/xiaoxiao/.npm/_cacache/index-v5/6a/90/1b26ae190af490d7fd39a6673109d8c5b482e769a00ccdba888e1885697c
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 501:20 "/Users/xiaoxiao/.npm"

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xiaoxiao/.npm/_logs/2021-02-24T08_13_50_717Z-debug.log

再继续查解决方法,发现单独执行命令可以顺利解决问题,代码如下: 

npm install -g react
npm install -g react-dom
npm install -g react-scripts

然后再重新创建 create-react-app  first-demo ,终于成功了!!!

Success! Created first-demo at /Users/xiaoxiao/Documents/MyReactDemo/first-demo
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 first-demo
  npm start

Happy hacking!

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐