Cli: [BUG] `prepare` and `prepack` scripts are not handled as documented when installing a git dependency

Created on 27 Sep 2020  路  8Comments  路  Source: npm/cli

Current Behavior:

I tested installing a git dependency which has either prepare or prepack script with npm CLI v7.0.0-beta.12 and confirmed the following behaviors.

  • a package with a prepare script: devDependencies are NOT installed but the prepare script is executed
  • a package with a prepack script: devDependencies are NOT installed and the prepack script is NOT executed

Expected Behavior:

  • a package with a prepare script: devDependencies are installed and the prepare script is executed
  • a package with a prepack script: devDependencies are installed and the prepack script is executed

    • Though I've not found any document saying that devDependencies are installed when installing a git dependency with a prepack script and actually they are not installed even when npm CLI v6 is used, I believe npm should install them since running a prepack script without installing devDependencies does not make sense.

Steps To Reproduce:

prepare:

// https://github.com/kimamula/prepare-test/blob/master/package.json
{
  "name": "prepare-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "prepare": "tsc"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "typescript": "^4.0.3"
  }
}
$ npm install github:kimamula/prepare-test
npm ERR! code 127
npm ERR! git dep preparation failed
npm ERR! command /Users/kenji/.nodenv/versions/12.18.3/bin/node /Users/kenji/.nodenv/versions/12.18.3/lib/node_modules/npm/bin/npm-cli.js install --only=dev --prod --ignore-prepublish --no-progress --no-save --cache=/Users/kenji/.npm/_cacache --prefer-offline=false --prefer-online=false --offline=false --before=
npm ERR! > [email protected] prepare
npm ERR! > tsc
npm ERR! npm WARN invalid config before="" set in command line options
npm ERR! npm WARN invalid config Must be one of: null, valid Date string
npm ERR! sh: tsc: command not found
npm ERR! npm ERR! code 127
npm ERR! npm ERR! path /Users/kenji/.npm/_cacache/tmp/git-clone-a73f300b
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c tsc
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /Users/kenji/.npm/_cacache/_logs/2020-09-27T06_13_19_941Z-debug.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/kenji/.npm/_logs/2020-09-27T06_13_19_972Z-debug.log

prepack:

// https://github.com/kimamula/prepack-test/blob/master/package.json
{
  "name": "prepack-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "prepack": "tsc"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "typescript": "^4.0.3"
  }
}
$ npm install github:kimamula/prepack-test

changed 1 package, and audited 1 package in 6s

found 0 vulnerabilities

-> tsc should generate index.js file, but it's not generated.

Environment:

  • OS: macOS 10.15.6
  • Node: 12.18.3
  • npm: 7.0.0-beta.12
Bug Release 7.x

All 8 comments

@kimamula just to confirm, does this behavior reflect how [email protected] works today? Or, have we changed how that works?

@darcyclarke The behavior of [email protected] is different (see #1229).

  • a package with a prepare script: working as expected (devDependencies are installed and the prepare script is executed)
  • a package with a prepack script: devDependencies are NOT installed but the prepack script is executed

I seem to be hitting a similar case but where the prepare script is running without dependencies being available under NPM 7. This particular dependency is not published to NPM, so I am installing it as a Git dependency specification, not sure if that is related.

With NPM 6, the following worked:

npm install --save-dev git+https://github.com/codemirror/google-modes.git#57b26bb0e76ca5d3b83b12faf13ce1054d34bdd

But with NPM 7 it fails, seemingly because the grammar-mode binary that this package's prepare script depends on is not available:

npm install --save-dev git+https://github.com/codemirror/google-modes.git#57b26bb0e76ca5d3b83b12faf13ce1054d34bdd
npm ERR! code 127
npm ERR! git dep preparation failed
npm ERR! command /home/aomarks/node/bin/node /home/aomarks/node/lib/node_modules/npm/bin/npm-cli.js install --only=dev --prod --ignore-prepublish --no-progress --no-save --cache=/home/aomarks/.npm/_cacache --prefer-offline=false --prefer-online=false --offline=false --before=
npm ERR! > [email protected] prepare
npm ERR! > npm run build && npm test
npm ERR! 
npm ERR! 
npm ERR! > [email protected] build
npm ERR! > npm run build-js && npm run build-ts && npm run build-c && npm run build-cpp && npm run build-clif && npm run build-fbs && npm run build-py && npm run build-go && npm run build-java && npm run build-html && npm run build-ng && npm run build-kotlin
npm ERR! 
npm ERR! 
npm ERR! > [email protected] build-js
npm ERR! > grammar-mode --es-module src/javascript.grammar --output src/javascript.mode.js && rollup -c rollup.config.js src/javascript.js -o dist/javascript.js
npm ERR! npm WARN invalid config before="" set in command line options
npm ERR! npm WARN invalid config Must be one of: null, valid Date string
npm ERR! sh: 1: grammar-mode: not found
npm ERR! npm ERR! code 127
npm ERR! npm ERR! path /home/aomarks/.npm/_cacache/tmp/git-clone-ae2eb4f5
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c grammar-mode --es-module src/javascript.grammar --output src/javascript.mode.js && rollup -c rollup.config.js src/javascript.js -o dist/javascript.js
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /home/aomarks/.npm/_cacache/_logs/2020-10-21T22_12_07_990Z-debug.log
npm ERR! npm ERR! code 127
npm ERR! npm ERR! path /home/aomarks/.npm/_cacache/tmp/git-clone-ae2eb4f5
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c npm run build-js && npm run build-ts && npm run build-c && npm run build-cpp && npm run build-clif && npm run build-fbs && npm run build-py && npm run build-go && npm run build-java && npm run build-html && npm run build-ng && npm run build-kotlin
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /home/aomarks/.npm/_cacache/_logs/2020-10-21T22_12_08_013Z-debug.log
npm ERR! npm ERR! code 127
npm ERR! npm ERR! path /home/aomarks/.npm/_cacache/tmp/git-clone-ae2eb4f5
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c npm run build && npm test
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /home/aomarks/.npm/_cacache/_logs/2020-10-21T22_12_08_023Z-debug.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/aomarks/.npm/_logs/2020-10-21T22_12_08_070Z-debug.log

This is a bug in pacote. https://github.com/npm/pacote/issues/53

Will be fixed in the next cli release (ie, tomorrow, likely included with the Node.js 15 release going out next week).

Yeah, those look like duplicates.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

goldingdamien picture goldingdamien  路  4Comments

zypA13510 picture zypA13510  路  4Comments

admosity picture admosity  路  4Comments

chrisspen picture chrisspen  路  3Comments

ahuglajbclajep picture ahuglajbclajep  路  3Comments