yarnpkg add --exact react react-dom react-scripts cra-template --cwd;core-js: Command failed.

安装react 脚手架发现报错

然后一不小心这个点了

error F:\react\study\my-react-app\node_modules\core-js: Command failed.
Exit code: 1
Command: node -e "try{require('./postinstall')}catch(e){}"
Arguments:
Directory: F:\react\study\my-react-app\node_modules\core-js
Output:
系统锟揭诧拷锟斤拷指锟斤拷锟斤拷路锟斤拷锟斤拷
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Aborting installation.
  yarnpkg add --exact react react-dom react-scripts cra-template --cwd F:\react\study\my-react-app has failed.

Deleting generated file... node_modules
Deleting generated file... package.json
Deleting my-react-app/ from F:\react\study
Done.

解决办法

把yarn卸载掉

npm uninstall yarn -g

然后就

Success! Created my-react-app at F:\react\study\my-react-app
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鈥檛 go back!

We suggest that you begin by typing:

  cd my-react-app
  npm start

Happy hacking!
 

初步分析

你本地安装yarn,下载依赖就是通过yarn去下载,这个时候安装脚手架会在core-js这里出现异常,然后就无法继续安装执行rm -rf命令删除掉node_module依赖文件就是下面报的错误

如果卸载yarn以后安装项目使用npm下载依赖

这里抛出异常以后就会接着继续安装依赖

综上所述应该是core-js这个依赖的问题 可跳转https://www.npmjs.com/package/core-js参考

接下来有空继续分析, core-js在vue-cli脚手架安装依赖的时候也会出问题,默认使用2.xcore-js版本但是4.x的脚手架需要升级到3.x的core-js

猜你喜欢

转载自blog.csdn.net/sunnyboysix/article/details/107148765