ci and install run preinstall lifecycle script at different times

(nmschulte) #1

This seems like a bug. Maybe it’s not a bug. :shrug:

What I Wanted to Do

Use a preinstall script to perform some development tasks before npm install (or npm ci) of a package for development. This script includes sanity checks for things like specifying the (non-public) registry and necessary authentication.

What Happened Instead

npm ci will try to contact the registry before the preinstall lifecycle script is run. npm install runs the preinstall lifecycle script before contacting the registry.

Reproduction Steps

$ mkdir npm-test && cd npm-test
$ npm init -y
$ sed -i 's/^    "test":.*$/    "preinstall": "echo PREINSTALL: ${npm_config_registry}"/' package.json
$ npm -d i
$ npm -d ci


Ideally npm i and npm ci in the “how to reproduce” section above are run with clean caches and empty node_modules.

Platform Info

$ npm --versions
{ npm: '6.8.0',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.15.1',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '',
  zlib: '1.2.11' }

$ node -p process.platform
(Daniel Stockman) #2

Definitely a bug of some sort. I’ve hit it with trying to pass package config to postinstall hooks that are expecting the env vars that npm was passing consistently prior to v6.6.0 to both npm install and npm ci.

1 Like