[BUG] npm install does not set $INIT_CWD correctly for some GitHub packages
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
INIT_CWD is supposed to point to the folder where npm i is executed. For some packages installed from GitHub, INIT_CWD points to a /.npm/_cacache folder. This problem prevents lifecycle scripts from knowing where the project folder is.
This is similar behavior as described in https://github.com/npm/cli/issues/3123.
Expected Behavior
$INIT_CWD should point to the folder where npm was executed.
Steps To Reproduce
-
In this environment...
System: Macbook Pro M1 Max running macOS Ventura 13.3.1 (a)
Node: v20.0.0
NPM: 9.6.4 -
With this config...
$ cd repos $ mkdir test_adt2 $ npm init -y -
Run '...'
$ pwd /Users/eedwards/repos/test_adt2 $ npm i github:eskwayrd/adt2 ...snip... npm ERR! code 1 npm ERR! git dep preparation failed npm ERR! command /usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/Users/eedwards/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run npm ERR! > antora-doc-tools@1.0.0 prepare npm ERR! > echo $INIT_CWD && node prepare.js npm ERR! npm ERR! /Users/eedwards/.npm/_cacache/tmp/git-cloneXL4RP5 ...snip...Notice that
echo $INIT_CWDshows a path in~/.npm, which is not the path where I executednpm i. -
See error...
Environment
- npm: 9.6.4
- Node.js: 20.0.0
- OS Name: macOS Ventura 13.3.1 (a)
- System Model Name: Macbook Pro
- npm config:
; copy and paste output from `npm config ls` here
; node bin location = /usr/local/bin/node
; node version = v20.0.0
; npm local prefix = /Users/eedwards/repos/test_adt2
; npm version = 9.6.4
; cwd = /Users/eedwards/repos/test_adt2
; HOME = /Users/eedwards
; 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
Reproduce the GitHub package installation and its prepare.js script using the command shown in the report. Start at the npm-cli.js invocation and trace how INIT_CWD is set during Git dependency preparation; done means the script reports the directory where npm install was executed rather than a ~/.npm/_cacache path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100