3

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?

Rey
  • 1,393
  • 1
  • 15
  • 24

1 Answers1

6

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
samanime
  • 25,408
  • 15
  • 90
  • 139
  • When I tried this, I ended up with multiple compilation errors that weren't there when I last committed the working version of the repo. I also just tried downloading the entire repo from our server and running "npm install" again. Still came up with errors, such as "Initializers are not allowed in ambient contexts." These errors weren't there before. I wonder if this is because supposedly minor updates (that should be non-breaking), actually ended up being so - and so the "npm update" I ran yesterday is still responsible for the errors I'm now seeing. Is there no fail-safe way to do this? – Rey May 02 '17 at 16:46
  • No. If you wipe your `node_modules`, and then `npm install`, it'll reset it to exactly what your `package.json` has. If you're still getting errors, it's most likely that your `package.json` is missing (or has something added) that you hadn't run `npm install` against yet. That happens sometimes if things are added without remembering to add `--save` or `--save-dev`. – samanime May 02 '17 at 16:54
  • So you mean that the errors would have been there before, it's just that "npm install" hadn't been run lately - and if there was something added in the meantime - those errors never showed up. Correct? So, my way forward now is to deal with the conflicts causing the errors, yes? – Rey May 02 '17 at 16:59