Reverting to Previous Version of Package.json When a Dependency Bug Arises

angular, javascript, npm, npm-install, npm-update

Solution

The process you described should work:

- Get an old copy of your `package.json` from your repository at the state you know it worked

- Run `rm -rf node_modules` to remove the `node_modules` folder

- Run `npm install` to install again

If that didn't work, verify that you:

- are in the correct directory (that should contain `package.json` and `node_modules`)

- have permissions to clean the `node_modules` folder (`chmod 777 node_modules`)

- the `package.json` that is written in the file system is actually the restored one (sometimes an IDE or Git can create a weird shadow copy where you think it's one way, but it's really another). You can tell this by using `cat package.json` and inspecting the output

Problem

While in the process of updating an Angular app I and colleagues are working on, I ended up running "npm update" when I meant to run "npm install". Doing so led me on a bit of a rabbit trail because of course now all my dependencies - AND their dependencies got updated in the process. From there I had to resolve certain conflicts to get the new versions to work correctly. However, this also led me to a point where a bug in one of those dependencies is preventing my app from booting up. According to the the Angular github repo, the issue is being worked on. My question is, how can I revert to my previous setup in the meantime? I tried copy and pasting the package.json file as it originally existed before my "npm update", deleting my "node modules" folder, and running "npm install" again. But this doesn't resolve the issue. Is there a way I can be assured of reverting to my previous working setup?

Original source