Any reason to ignore the package-lock.json in .gitignore
Author: elchininetCreated Jun 19, 2021Updated Apr 21, 2024
LabelsDiscussion - Questionnpm install
Hello:
I’ve noticed that package-lock.json is ignored in .gitignore. This change was introduced in #2149 and there is a comment asking for its deletion and another comment stating that it is generated automatically by npm so it has been added to .gitignore.
But it is important to know what is the intention of package-lock.json and why it is important to keep it in the repository:
- Describe a single representation of a dependency tree such that teammates, deployments, and continuous integration are guaranteed to install exactly the same dependencies.
- Provide a facility for users to "time-travel" to previous states of
node_moduleswithout having to commit the directory itself. - To facilitate greater visibility of tree changes through readable source control diffs.
- Optimize the installation process by allowing npm to skip repeated metadata resolutions for previously-installed packages.
- As of npm v7, lockfiles include enough information to gain a complete picture of the package tree, reducing the need to read package.json files, and allowing for significant performance improvements.
The most important thing about package-lock.json is to ensure when one runs npm install one will get a known-to-work state of the entire tree (which is not ensured if this file is removed and each user has their own version of the tree).
But maybe I don’t have the entire context of this change, there was any specific reason for it?
Source: sass/node-sass