[BUG] `npm install` strips `#<commit>` from git `resolved` URLs in `yarn.lock`, installing HEAD instead of the locked commit
Los mantenedores suelen responder en 2 días
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 18/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- git, javascript, nodejs
Línea de trabajo
The stripping happens in YarnLock#parse in workspaces/arborist/lib/yarn-lock.js, where metadata[1].replace(/#.*/, '') removes the #<commit> fragment from git resolved URLs. Read YarnLock.fromTree alongside it, since that path writes the fragment back. Done means a git resolved keeps its commit hash through parse, and npm install --allow-git=root against the sample yarn.lock installs the locked commit with npm ls exiting 0. Linked PR #10348 is already open against this, so check it before starting.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
This is not just a request to bump a dependency for a CVE
- This is not solely a request to bump a dependency for a CVE
Current Behavior
When package-lock.json is absent and a Yarn v1 yarn.lock is present, npm install uses yarn.lock to seed the tree (Shrinkwrap#checkYarnLock), but strips #<commit> from git+... resolved entries.
For example, with "abbrev": "git+https://github.com/isaacs/abbrev-js.git#semver:^1.1.0" in package.json and a yarn.lock generated by [email protected] locking [email protected] at commit a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb:
npm install --allow-git=rootfails withEALLOWGITbecausenpmfetches default-branchHEAD([email protected]), which makes the root edge invalid (edge.valid === false) and causes#extractOrLinkto treat the root dependency as a non-root git dependency:
npm error code EALLOWGIT
npm error Fetching non-root packages of type "git" have been disabled
npm error Refusing to fetch "abbrev@git+https://github.com/isaacs/abbrev-js.git"
npm install --allow-git=all(and defaultnpm installon npm 11) ignores both the commit inyarn.lockand#semver:^1.1.0inpackage.json, installs[email protected]fromHEAD, writes"resolved": "git+https://github.com/isaacs/abbrev-js.git"without a commit hash topackage-lock.jsonandyarn.lock, and leavesnpm lsfailing withELSPROBLEMS:
npm warn skipping integrity check for git dependency https://github.com/isaacs/abbrev-js.git
added 1 package in 992ms
[email protected] /tmp/repro
└── [email protected] invalid: "git+https://github.com/isaacs/abbrev-js.git#semver:^1.1.0" from the root project (git+https://github.com/isaacs/abbrev-js.git)
npm error code ELSPROBLEMS
npm error invalid: [email protected] /tmp/repro/node_modules/abbrev
Removing yarn.lock and running npm install --allow-git=root installs [email protected] (git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb) cleanly. The same stripping also occurs when package.json pins an exact commit hash (git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb) alongside yarn.lock.
Root cause: in workspaces/arborist/lib/yarn-lock.js, YarnLock#parse runs metadata[1] = metadata[1].replace(/#.*/, '') on every resolved value to remove legacy tarball #<sha1> shasums, which also strips the #<commit> fragment from git+... URLs (even though YarnLock.fromTree emits resolved "git+...#<commit>").
Expected Behavior
YarnLock#parse preserves #<commit> fragments on git resolved URLs so npm install --allow-git=root installs the locked commit ([email protected] at a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb), records the commit hash in package-lock.json, and npm ls exits 0.
Steps To Reproduce
WORK=$(mktemp -d)
cd "$WORK"
cat > package.json << 'EOF'
{
"name": "repro",
"version": "1.0.0",
"dependencies": {
"abbrev": "git+https://github.com/isaacs/abbrev-js.git#semver:^1.1.0"
}
}
EOF
# Generated by [email protected] for the package.json above
cat > yarn.lock << 'EOF'
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"abbrev@git+https://github.com/isaacs/abbrev-js.git#semver:^1.1.0":
version "1.1.1"
resolved "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb"
EOF
# 1. Fails with EALLOWGIT on npm 12 under --allow-git=root
npm install --allow-git=root --no-audit --no-fund
# 2. Installs HEAD ([email protected]) instead of locked 1.1.1 under --allow-git=all
npm install --allow-git=all --no-audit --no-fund
npm ls
Environment
- npm: 12.2.3 (bundles
@npmcli/arborist10.0.5; also reproduces onnpm/clilatestat787f1520faand npm 11.21.3) - Node.js: v24.22.2
- OS Name: Debian GNU/Linux 12 (bookworm), Linux 6.1 x86_64
- npm config:
; defaults (empty .npmrc)
Credit: https://ucsbplse.github.io/
- Lenguaje dominante
- JavaScript
- Estrellas
- 10.3k
- Forks
- 5k
- Merge medio
- 4 d 11 h
- PR fusionados (30 d)
- 26
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de npm/cli
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 2 días
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endingsPosiblemente ocupada @saruk-vedant la tomó hace 7 días. AbiertoBug Needs Triage Triage Requested
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
npm/cli#10316 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyPosiblemente ocupada @drawliin la tomó hace 42 días. Abiertocmd:delete Priority 3
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 2 días
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. AbiertoEngineering Priority 1
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
Los mantenedores suelen responder en 2 días
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysPosiblemente ocupada @greenlincoln05 la tomó hace 63 días. AbiertoPriority 3
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
npm/cli#10018 · 2 comentarios ·
Los mantenedores suelen responder en 2 días
Issues similares
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
githubnext/gh-aw-workshop#6332 ·
Los mantenedores suelen responder en 1 día
-
App Designer bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
avniproject/avni-webapp#1858 ·
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 96/100
hiero-ledger/hiero-sdk-js#4834 ·
Los mantenedores suelen responder en 1 día
-
[组件名称] 描述问题的标题Abierto🐞 bug 🧐 unconfirmed
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Tencent/tdesign-miniprogram#4744 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Y-axis tooltip hides near the bottom of the plot while the y crosshair stays visiblePosiblemente ocupada @lazerg la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
apexcharts/apexcharts.js#5449 ·
Los mantenedores suelen responder en 3 días