[BUG] `npm install` modifies yarn.lock in incorrect ways
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.1k
- Forks
- 4.7k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 19
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
If you run npm install in a project that has a yarn.lock file, npm changes both the syntax, data and order of yarn.lock file.
Changes I've spotted that shouldn't happen:
- npm adds double-quotes around everything (
is-number@^7.0.0:becomes"is-number@^7.0.0":,versionbecomes"version"and so on) - Registry URLs get overwritten (
"https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"becomes"https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz") - Order of keys becomes shuffled (
yarn.lockhasversion,resolved,integrityin that order, afternpm install, the order becomesintegrity,resolved,version)
Expected Behavior
No commands run with npm should modify files npm doesn't have anything to do with, namely yarn.lock which is managed by a different program than npm.
Steps To Reproduce
cd $(mktemp -d)Create new temporary directory for a test projectnpm init --yesCreate new package.jsonnpm install --save is-numberAdd a dependencyyarn installInstall dependencies via yarn, creating theyarn.lockfilecp yarn.lock yarn.lock.originalSave a copy of the originalyarn.lockfilenpm installRun npm install again which modifies theyarn.lockfile unexpectedlydiff yarn.lock yarn.lock.originalshow the difference between the npm-modified yarn.lock file with the original one that yarn itself produces
Environment
- npm:
8.13.2 - Node.js:
v18.4.0 - OS Name:
Arch Linux - System Model Name:
Desktop - npm config:
; "user" config from /home/user/.npmrc
//registry.npmjs.org/:_authToken = (protected)
; node bin location = /home/user/.nvm/versions/node/v18.4.0/bin/node
; node version = v18.4.0
; npm local prefix = /tmp/tmp.YKcr2lMqCS
; npm version = 8.13.2
; cwd = /tmp/tmp.YKcr2lMqCS
; HOME = /home/user
; Run `npm config ls -l` to show all defaults.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the listed temporary-project commands and compare yarn.lock with yarn.lock.original. Trace the npm install path that handles an existing yarn.lock; done means npm install leaves yarn.lock unchanged, with coverage for the quoted keys, registry URLs, and key ordering described in the report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100