Why does removing package-lock.json break a build, but running "npm install" without deleting it doesn't?

Viewed 2357

I have a project where I removed some no-longer needed libraries from my package.json file, removed node_modules, ran npm install, and everything continued to work as expected.

Unfortunately if I follow the same steps above after having deleted package-lock.json, my build suddenly breaks. A new package-lock.json is generated but I now get hundreds of deprecation warnings from some dependencies and even though the project continues to build those same dependencies will break in unexpected places.

If I revert to the previous package-lock.json and again run the same steps (remove node_modules, run npm install), the warnings once again disappear and the build is once more in a safe state.

My understanding is that package-lock.json will update every time we run npm install with the most recent package versions, respecting the caret^ and tilde~ restrictions. Does this update differ if we have an existing package-lock.json vs a fresh install?

Some additional details:
-I'm using Vue and vue-cli and my build scripts run vue-cli-service build.
-This happened in between a migration from one css framework to another (bootstrap-vue/vuetify) so there may be sub-dependencies that both frameworks include that are the same
-Sass is what was throwing hundreds of deprecation warnings

Even if there is somehow a conflict between sub-dependencies I'm still confused why updating a package-lock.json with npm install works great but running npm install after deleting that file creates a new package-lock.json that breaks. This happens consistently over many attempts.

0 Answers
Related