React使用create-react-app 创建项目失败,解决方法
·
运行命令
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!
更多推荐



所有评论(0)