cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] prepare script doesn't see node_modules bin executables

Open aovchinn opened this issue 2 years ago • 6 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

I want to have one command to install cli module from git, but it is not possible as prepare step doesn't get node_modules (cli written with typescript, so it needs npx tsc in the prepare step)

npm i -g git+ssh: ... fails with

'tsc' is not recognized as an internal or external command

Expected Behavior

prepare should take dev and dependencies, and run itself before finishing install as typescript is listed in dependencies tsc cannot be missing

Steps To Reproduce

repo: https://github.com/aovchinn/test-ssh-git-npm-install/tree/main

  1. In windows
  2. With npm 9
  3. Run 'npm install -g [email protected]:aovchinn/test-ssh-git-npm-install.git'
  4. See error...
PS C:\Users\xxxx\code\test-ssh-git-npm-install> npm install -g [email protected]:aovchinn/test-ssh-git-npm-install.git
npm ERR! code 1
npm ERR! git dep preparation failed timing reifyNode:node_modules/test-ssh-git-n
npm ERR! command C:\Program Files\nodejs\node.exe C:\Users\xxxx\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js install --force --cache=C:\Users\xxxx\AppData\Local\npm-cache --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! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! code 1
npm ERR! npm ERR! path C:\Users\xxxx\AppData\Local\npm-cache\_cacache\tmp\git-cloneXzSIOZ
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command C:\Windows\system32\cmd.exe /d /s /c npx tsc
npm ERR! npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! npm WARN exec The following package was not found and will be installed: [email protected]
npm ERR! npm ERR! 'tsc' is not recognized as an internal or external command,
npm ERR! npm ERR! operable program or batch file.
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in:

Environment

  • npm: 9.6.6
  • Node.js: v16.20.0
  • OS Name: win 10
  • System Model Name: ? PC
  • npm config:
; "builtin" config from C:\Users\treovchinn\AppData\Roaming\npm\node_modules\npm\npmrc

prefix = "C:\\Users\\treovchinn\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v16.20.0
; npm local prefix = C:\Users\treovchinn\code\test-ssh-git-npm-install
; npm version = 9.6.6
; cwd = C:\Users\treovchinn\code\test-ssh-git-npm-install
; HOME = C:\Users\treovchinn
; Run `npm config ls -l` to show all defaults.

aovchinn avatar May 08 '23 20:05 aovchinn

did some debugging seems like in rebuild _PACOTE_NO_PREPARE_ flag is not checked this is inside spawned npm process by node_modules\npm\node_modules\pacote\lib\util\npm.js you can see that event is prepare - and flag is set on process.env image

aovchinn avatar May 09 '23 19:05 aovchinn

here we can see that node_modules are missing in realpath of this Link type node image

aovchinn avatar May 09 '23 20:05 aovchinn

is it ok to ping isaacs ? as he added this PACOTE_NO_PREPARE flag https://github.com/npm/pacote/commit/3d4ccac9593010ac1d5514a4c11949a0ed05e5a9

aovchinn avatar May 09 '23 20:05 aovchinn

could be also this https://github.com/npm/cli/commit/181eabf132c823af086380368de73d2f42e5aac1

aovchinn avatar May 09 '23 20:05 aovchinn

@isaacs @ruyadorno is PACOTE_NO_PREPARE flag required there ? https://github.com/npm/cli/issues/6435#issuecomment-1540805640

aovchinn avatar May 25 '23 07:05 aovchinn

Run into the same issue today, with npm git install:

npm i -g https://github.com/wasp-lang/wasp-app-runner#80491aab8146823997e1f24aa92b045aa796d20d
// package.json
// ...
    "build": "tsc",
    "prepare": "npm run build",
// ...
  "devDependencies": {
    "@types/node": "^22.15.12",
    "typescript": "^5.8.3"
  }
}

Environment:

35 verbose os Darwin 24.3.0
36 verbose node v22.15.0
37 verbose npm  v10.9.2

Error:

npm error code 127
npm error git dep preparation failed
npm error command /Users/mindek/.nvm/versions/node/v22.15.0/bin/node /Users/mindek/.nvm/versions/node/v22.15.0/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/Users/mindek/.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 error npm warn using --force Recommended protections disabled.
npm error npm error code 127
npm error npm error path /Users/mindek/.npm/_cacache/tmp/git-clonecZYzlj
npm error npm error command failed
npm error npm error command sh -c npm run build
npm error npm error > [email protected] build
npm error npm error > tsc
npm error npm error npm warn using --force Recommended protections disabled.
npm error npm error sh: tsc: command not found

I will probably prebuild the app instead, as I don't have any OS dependencies.

FranjoMindek avatar Jun 02 '25 12:06 FranjoMindek

Closing This looks like the duplicate or similer of #8440. keeping the new one open.

milaninfy avatar Jul 29 '25 14:07 milaninfy