user7854319
user7854319

Reputation: 65

How to run eject in my react app?

I want to eject my react app,so I use code:npm run eject in cmmand line.But it told me I failed.And these are all logs:

Remove untracked files, stash or commit any changes, and try again.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] eject: `react-scripts eject`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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!     C:\Users\Pigpigever\AppData\Roaming\npm-cache\_logs\2017-08-
14T09_03_14_398Z-debug.log

Can anyone tell me how to do ?

Upvotes: 4

Views: 15576

Answers (8)

NH Dalim
NH Dalim

Reputation: 352

You have to follow these steps:

  1. git add .

  2. You must have to commit before install eject: git commit -m "save before ejecting"

  3. run eject: if you use yarn, you should type this on your terminal: yarn eject or npm run eject

  4. one config folder will be added to your project, and inside this folder, you will find one file called "webpack.config.js". searching "css-loader" or type (Ctrl+f) for searching specific words. you will find below code in this file.

    {
       loader: require.resolve('css-loader'),
       options: cssOptions,      
    }

change it by:

{
   loader: require.resolve('css-loader'),
   options: {
      modules: {
        mode: "local",
        localIdentName: "[name]_[local]_[hash:base64:5]"
      },
      import: true,
      importLoaders: true
    }     
}
  1. the most important part is now you must restart your code editor, sometimes it can be 4/5 times.

The above steps worked for me. Hopefully, it will also work for you.

Enjoy

Upvotes: 0

Ashutosh yadav
Ashutosh yadav

Reputation: 1

m ERR! code ENOENT

npm ERR! syscall open

npm ERR! path /home/red/Desktop/react-course/package.json

npm ERR! errno -2

npm ERR! enoent ENOENT: no such file or directory, open '/home/red/Desktop/react-course/package.json'

npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent

If someone facing this issue then just do this:-

cd your project name (for e.g react-assignment)

npm run eject

Upvotes: 0

Gaurav
Gaurav

Reputation: 902

When you use 'create-react-app', it prevents you from ejecting your app without first having committed any outstanding changes to Git. That is the sole reason for the error. Go to your github account create a repository, clone it to your base system . then use 'npm-run-eject'. Mine worked with this. I hope your problem gets resolved too :)

HAPPY_CODING

Upvotes: 1

Sutirtha Rej
Sutirtha Rej

Reputation: 15

  • In the base directory do:
git init
  • go inside the react folder ,then do
git add .
  • then commit it
git commit -m "some msg" 
  • then
yarn eject

or

npm run eject

Upvotes: 1

I had the same issue. I did the following to fix it.

rm -rf .gitignore
rm -rf .git

finally

npm run eject

Ejected successfully! :)

Upvotes: 0

Archit Pandey
Archit Pandey

Reputation: 175

Please commit all the changes you have done and then retry to eject using the command - 'npm run eject'

Upvotes: 0

Mr Singh
Mr Singh

Reputation: 4230

You can use:

git add .
git commit -am "Save before ejecting"

And try it again

Upvotes: 4

Joe Clay
Joe Clay

Reputation: 35817

That error message isn't massively clear (in fact, there's an open issue on GitHub to improve it).

create-react-app prevents you from ejecting your app without first having committed any outstanding changes to Git - this is so that if ejecting breaks things (or if you just decide you've made a mistake and want to go back), you're able to restore your project to how it was before.

As the error message says - to get the command to work, you'll need to:

  • Add any untracked files you want to keep to your Git repository.
  • Remove any untracked files you don't want to keep (either by deleting them or adding them to your .gitignore).
  • Commit your changes, or stash them if you'd like to commit them at a later time.

Upvotes: 14

Related Questions