新手使用create-react-app命令创建一个项目, 运行npm run eject报错。已解决,感谢!

#1

环境:Mac系统,我随便在任何一个地方使用create-react-app命令创建一个项目,运行npm run eject命令暴露配置文件都报这个错误。git提交?怎么会这样呢,我什么都还没弄,才刚创建项目就让我提交git? 而且还是在这个项目根目录之外的文件。

This git repository has untracked files or uncommitted changes:

Remove untracked files, stash or commit any changes, and try again.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-app@0.1.0 eject: `react-scripts eject`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the react-app@0.1.0 eject script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
1 Like
#2

React Chine 没人了吗?

#3

你有改动项目的其他内容之后 再尝试eject就会这样

#4

感谢!我刚create-react-app创建项目,什么都还没动,就去执行npm run eject的。怎么办? 还没解决呀

#5

git add .

然后

git commit -m "init"

然后再npm run eject

#6

我的是MAC系统,按你的操作了一般还是不行。
执行git commit -m "init"后显示:
Changes not staged for commit:
deleted: …/react/react-app/.gitignore
deleted: …/react/react-app/README.md
deleted: …/react/react-app/package-lock.json
deleted: …/react/react-app/package.json
deleted: …/react/react-app/public/favicon.ico
deleted: …/react/react-app/public/index.html
deleted: …/react/react-app/public/manifest.json
deleted: …/react/react-app/src/App.css
deleted: …/react/react-app/src/App.js
deleted: …/react/react-app/src/App.test.js
deleted: …/react/react-app/src/index.css
deleted: …/react/react-app/src/index.js
deleted: …/react/react-app/src/logo.svg
deleted: …/react/react-app/src/registerServiceWorker.js
deleted: …/react/react-app/yarn.lock
Untracked files:
中间省略内容
中间省略内容
中间省略内容
。。。。。。
no changes added to commit
PC-194-iMac:react-app public1$ npm run eject

react-app@0.1.0 eject /Users/public1/Desktop/react-app
react-scripts eject

? Are you sure you want to eject? This action is permanent. Yes
This git repository has untracked files or uncommitted changes:

Desktop/react/react-app/.gitignore
D Desktop/react/react-app/README.md
D Desktop/react/react-app/package-lock.json
D Desktop/react/react-app/package.json
D Desktop/react/react-app/public/favicon.ico
D Desktop/react/react-app/public/index.html
D Desktop/react/react-app/public/manifest.json
D Desktop/react/react-app/src/App.css
D Desktop/react/react-app/src/App.js
D Desktop/react/react-app/src/App.test.js
D Desktop/react/react-app/src/index.css
D Desktop/react/react-app/src/index.js
D Desktop/react/react-app/src/logo.svg
D Desktop/react/react-app/src/registerServiceWorker.js
D Desktop/react/react-app/yarn.lock
中间省略内容
中间省略内容
中间省略内容
。。。。。。

Remove untracked files, stash or commit any changes, and try again.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-app@0.1.0 eject: react-scripts eject
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-app@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/public1/.npm/_logs/2018-06-07T10_00_23_140Z-debug.log

#7

再试一次

git add .

然后(注意这里是 am)

git commit -am "Save before ejecting"
#8

应该是了。我自己在桌面创建了一个文件夹,把这个文件夹里的react-app项目commit后,再执行npm run eject就可以了。
不这样的话,我把项目放在任何地方去执行npm run eject还是出git问题(它居然会往上层去找没提交的文件,一直找到Desktop文件夹的上一层,然后显示一堆无关的文件夹要我提交,会把react-app这个项目逐渐一层一层的上层文件全部给显示出来要我提交,注意是全部文件。我的MAC目录可能有杂乱的git项目。
不过最后还是成功了:

react-scripts eject

? Are you sure you want to eject? This action is permanent. Yes
Ejecting…

Copying files into /Users/public1/Desktop/HTML-Study/react-app
Adding /config/env.js to the project
Adding /config/paths.js to the project
Adding /config/polyfills.js to the project
Adding /config/webpack.config.dev.js to the project
Adding /config/webpack.config.prod.js to the project
Adding /config/webpackDevServer.config.js to the project
Adding /config/jest/cssTransform.js to the project
Adding /config/jest/fileTransform.js to the project
Adding /scripts/build.js to the project
Adding /scripts/start.js to the project
Adding /scripts/test.js to the project

Updating the dependencies
Removing react-scripts from dependencies
Adding autoprefixer to dependencies
Adding babel-core to dependencies
Adding babel-eslint to dependencies
Adding babel-jest to dependencies
Adding babel-loader to dependencies
Adding babel-preset-react-app to dependencies
Adding babel-runtime to dependencies
Adding case-sensitive-paths-webpack-plugin to dependencies
Adding chalk to dependencies
Adding css-loader to dependencies
Adding dotenv to dependencies
Adding dotenv-expand to dependencies
Adding eslint to dependencies
Adding eslint-config-react-app to dependencies
Adding eslint-loader to dependencies
Adding eslint-plugin-flowtype to dependencies
Adding eslint-plugin-import to dependencies
Adding eslint-plugin-jsx-a11y to dependencies
Adding eslint-plugin-react to dependencies
Adding extract-text-webpack-plugin to dependencies
Adding file-loader to dependencies
Adding fs-extra to dependencies
Adding html-webpack-plugin to dependencies
Adding jest to dependencies
Adding object-assign to dependencies
Adding postcss-flexbugs-fixes to dependencies
Adding postcss-loader to dependencies
Adding promise to dependencies
Adding raf to dependencies
Adding react-dev-utils to dependencies
Adding resolve to dependencies
Adding style-loader to dependencies
Adding sw-precache-webpack-plugin to dependencies
Adding url-loader to dependencies
Adding webpack to dependencies
Adding webpack-dev-server to dependencies
Adding webpack-manifest-plugin to dependencies
Adding whatwg-fetch to dependencies

Updating the scripts
Replacing “react-scripts start” with “node scripts/start.js”
Replacing “react-scripts build” with “node scripts/build.js”
Replacing “react-scripts test” with “node scripts/test.js”

Configuring package.json
Adding Jest configuration
Adding Babel preset
Adding ESLint configuration

Ejected successfully!

Please consider sharing why you ejected in this survey:
http://goo.gl/forms/Bi6CZjk1EqsdelXk1

#9

欢迎使用我的

#10

要在Mac桌面新建文件夹才可以,其他方法试了好像都报
This git repository has untracked files or uncommitted changes:
Remove untracked files, stash or commit any changes, and try again.

#11

我也出现的这样的问题,想知道具体是怎么解决的,我现在对他说的git有点懵

#12

create-react-app my-react-app
cd my-react-app
git init
git add .
git commit -m ‘Saving before ejecting’
npm run eject
按照以上顺序就可以正常使用
主要问题是脚手架添加.gitgnore文件,但是却没有本地仓库

#13

把node版本升级一下 10.0
或者 重新下载一个
然后 重新看下环境变量有没有配好 :grinning:

#14

感谢,用这个确实解决了,但是需要修改提交的描述,一直用同一个还是会报错。我换了一个提交的描述就成功了

#15

刚开始学习如何搭建react项目遇到问题,看到你的回答,非常感谢!!