Next.js incorrectly patches package-lock.json version 3
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #202204271406~1651504840~22.04~63e51bd SMP PREEMPT Mon May 2 15:
Binaries:
Node: 16.15.0
npm: 8.9.0
Yarn: 1.22.18
pnpm: N/A
Relevant packages:
next: 12.1.6
react: 18.1.0
react-dom: 18.1.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
There are 3 package-lock.json
versions. Version 1 uses the dependencies
field. Version 3 uses the packages
field. Version 2 combines both for backwards compatibility.
Next.js assumes the dependencies
field as the source of truth with a fallback to an empty object, but this is absent in package-lock.json
version 3. It will then make unnecessary requests to the npm registry and wrongfully strip the dev
field for each dependency
The logic for this is in packages/next/lib/patch-incorrect-lockfile.ts
.
Expected Behavior
Next.js patches the lockfile packages
field only if the packages
field is incomplete and not make unnecessary requests.
To Reproduce
recma-nextjs-static-props is a minimal Next.js project. and can be used as a project. Clone it, regenerate the lockfile, git add it
git clone git@github.com:remcohaszing/recma-nextjs-static-props.git
cd recma-nextjs-static-props
rm package-lock.json
npm install
git add .
Now run npm run dev
to see the lockfile is being changed by Next.js.
npm run dev
git diff
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Hi, this has been updated in
v12.1.7-canary.7
of Next.js, please update and give it a try!I opened a PR here https://github.com/vercel/next.js/pull/36959 to ensure the different lockfile versions are handled, thanks @remcohaszing for describing the differences there and also added an env variable
NEXT_IGNORE_INCORRECT_LOCKFILE
to allow skipping this check altogether.