29

I have just executed the ng eject command. But now I need to revert it, and continue to use ng commands. Is it possible?

I would be grateful for any help.

0

3 Answers 3

69

At https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/tasks/build.ts#L27 (current angular CLI version: 1.0.1) there is a condition:

if (config.project && config.project.ejected) {
  throw new SilentError('An ejected project cannot use the build command anymore.');
}

when you run ng-eject, package.json file is modified with new npm scripts, webpack.config.js file is added or replaced and ejected flag is added to your .angular.cli.json:

"project": {
  "name": "YOUR PROJECT NAME",
  "ejected": true
},

So, just remove "ejected" flag from your .angular.cli.json file:

or change this flag to false:

"project": {
  "name": "YOUR PROJECT NAME",
  "ejected": false
}
Sign up to request clarification or add additional context in comments.

4 Comments

Very helpful answer!I managed to load bootstrap this way!It seems that ng serve is not equal to npm run build & npm start
If you do the ejection in an isolated commit you might be able to revert the change later by rolling back that commit right?
actually only package.json you may want to revert, since ng eject may change your scripts section and add dev dependencies (loaders) needed for webpack. Although I noticed that running ng eject with -f flag merges old npm scripts with new added ones, but it should be checked. So, I think, that if your old npm scripts after ng eject are still in package.json and you do not care about loaders, just changing or removing "ejected" flag within .angular.cli.json and removing *webpack.config.js * would be enough and you may run all ng commands again. ng eject does not change any custom or core code
It's a bit inferred above, but if you proceed later to run ng eject again (if needed for flags, etc.) after having set ejected:false you'll get an error about project.json and that it must not contain a build script. You'll need to revert the changes within the scripts section as well. If you lost the changes, just fire up a new project as a means to an end and copy out the scripts section.
3

With current version of angular cli you need to mark ejected:false or remove the ejected property inside file angular-cli.json file instead of package.json file

Comments

1

This command makes the build configuration part of your project and gets rid of Angular CLI. And also set “ejected”: true in angular-cli.json file , create new file webpack.config.js in project root, and modified run scripts in package.json.

Finally, to undo the ng-eject command it is necessary to modify the package.json file again

Comments