TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Should you commit package-lock.json?

3 点作者 wawhal超过 6 年前
Hello HN,<p>We are trying to decide if we should commit package-lock to version control for our JavaScript project.<p>It is generally considered a good practice to commit package-lock to version control to avoid breaking anything due to the dependency updates and thus we have been committing it till now.<p>However, we are facing some problems. Everytime we run `npm install`, package-lock is overwritten whenever a new version is detected from `^` in package.json. This causes a lot of merge conflicts which are impractical to merge in the long run.<p>We were thinking of freezing the dependency versions in `package.json` itself and update them only when we really need to update them. In this way, we do not need to maintain package-lock. But this does not let us auto update the deps with incremental bug fixes that are released in the minor versions.<p>What do you people think?

2 条评论

xyzzy123超过 6 年前
For an application, yes, commit the lock file. TL:DR; use “npm ci”, not “npm i”.<p>This has several benefits; a) You know if a test fails, you broke something. Not a bug caused by dep shift. b) Your team is using same versions of deps during dev (reduces “works on my computer” moments) c) Your builds are more reproducible. You can be more confident that you can exactly build say, last month’s version of the app and have it work the same way it did back then.<p>Re: the noise problem, recommend using “npm ci” as the default and “npm i” only where you’re planning to update deps. This is less work than “freezing” stuff in package.json and also addresses the problem of transitive deps (the deps if your deps, which you would not really want to put in package.json anyway).<p>Use npm audit to detect stuff that <i>needs</i> updating and treat periodic dep updates as a janitorial task. When you do updates, make a PR with just the dep updates (plus any changes needed for them to work) and make sure all the tests pass. You can mostly automate this.<p>As a side note, the docs explicitly call out that the file is intended to be committed: <a href="https:&#x2F;&#x2F;docs.npmjs.com&#x2F;files&#x2F;package-lock.json" rel="nofollow">https:&#x2F;&#x2F;docs.npmjs.com&#x2F;files&#x2F;package-lock.json</a>
quantummkv超过 6 年前
Have you looked at yarn? From my experience yarn does not change its lock file unless you explicitly change your dependencies.