解决create-react-app后,运行npm run eject报错问题。

  • 问题重现:在Mac环境下使用create-react-app脚手架工具新建项目后,运行npm run eject后报错,报错信息如下:
Remove untracked files, stash or commit any changes, and try again.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mymanagers@0.1.0 eject: `react-scripts eject`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the mymanagers@0.1.0 eject script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2019-07-16T10_16_47_555Z-debug.log
  • 问题原因:脚手架工具为您的项目添加了.gitgnore文件,但是却没有本地仓库。
  • 解决办法:
#cd 你的项目目录
#git init
#git add .
#git commit -m "saving before ejecting"
#npm run eject
  • 补充知识:eject(弹射)命令做的事情。将潜藏在react-script中的一系列技术栈配置项都弹射到应用的顶层,然后就可以更灵活的定制研究修改这些配置细节。
  • 执行 npm run eject 之后会生成新的文件:
    eject生成的目录结构.png
  • 因reject过程 不可逆,所以非必须可以不必执行此操作。
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容