Skip to content

add package-lock=true to .npmrc #7676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

add package-lock=true to .npmrc #7676

wants to merge 2 commits into from

Conversation

mcollina
Copy link
Member

As titled. A user can override this with their global .npmrc setting.

Note that the project does not build if the deps are not installed from the lockfile.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@Copilot Copilot AI review requested due to automatic review settings April 23, 2025 14:26
@mcollina mcollina requested a review from a team as a code owner April 23, 2025 14:26
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Files not reviewed (1)
  • .npmrc: Language not supported

Copy link

vercel bot commented Apr 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview Apr 23, 2025 5:06pm

@codecov-commenter
Copy link

codecov-commenter commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.61%. Comparing base (139b316) to head (e16aaa9).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7676      +/-   ##
==========================================
- Coverage   74.63%   74.61%   -0.03%     
==========================================
  Files          96       96              
  Lines        7689     7689              
  Branches      192      192              
==========================================
- Hits         5739     5737       -2     
- Misses       1948     1950       +2     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@avivkeller
Copy link
Member

Can you elaborate why this is needed?

What are the consequences of not doing this?

@MattIPv4
Copy link
Member

Per the docs, https://docs.npmjs.com/cli/v11/using-npm/config#package-lock, this is set to true by default -- why do we need to explicitly set it?

@mcollina
Copy link
Member Author

Because quite a few high-profile maintainers (including me) set this to false by default as it's way too much work to keep this up-to-date over 500+ projects. Also, it doesn't hurt to add it.

Note it would not be needed if the project could build without that file - currently it doesn't . My guess is some dependencies are not really following semver.

@avivkeller
Copy link
Member

Note it would not be needed if the project could build without that file - currently it doesn't . My guess is some dependencies are not really following semver.

We should look into that

@MattIPv4
Copy link
Member

MattIPv4 commented Apr 23, 2025

Ah, I see, makes sense to me to set it then 👍 Would it be worth adding a comment above the line explaining why we're setting what is a default?

Co-authored-by: Aviv Keller <me@aviv.sh>
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
@avivkeller
Copy link
Member

Note it would not be needed if the project could build without that file - currently it doesn't . My guess is some dependencies are not really following semver.

I am able to build with a deleted package-lock.json file, can you show the error you face when trying to build without the file? It would certainly help with reproducing and resolving the error.

git clean -dfX # Remove all non-tracked files
rm package-lock.json
npm i
npm build

@bjohansebas
Copy link
Member

Note it would not be needed if the project could build without that file - currently it doesn't . My guess is some dependencies are not really following semver.

It's a precaution to avoid breaking production and to ensure everyone has the same development environment. It's a good practice, and that's why deleting the package-lock isn't an option I see as viable

@@ -1,2 +1,4 @@
# See bug in peerdeps resolution: https://github.com/npm/cli/issues/2999
legacy-peer-deps = false
# TODO(@mcollina): Currently, the lockfile is needed to build, so we explicitly require it's use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in my previous comment, it's a way to prevent breaking production and to ensure we all share the same development environment. So a comment like that can be useful, and it’s worth mentioning that some developers disabled it for a specific reason.

@avivkeller
Copy link
Member

Closing due to #7662

@avivkeller avivkeller closed this May 3, 2025
@avivkeller avivkeller deleted the add-npmrc branch May 3, 2025 18:33
@mcollina
Copy link
Member Author

mcollina commented May 4, 2025

pnpm suffers from the same issue, and it's 100% irrelevant to why this is needed.

@MattIPv4
Copy link
Member

MattIPv4 commented May 4, 2025

Given we no longer have an npmrc file at all, could you not just have your own locally and add it to your local gitignore, if this is something your setup needs still?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants