npm ci doesn't respect .npmrc variables

What I Wanted to Do

TL;DR
I wanted npm ci to catch up .npmrc variables.


We have a requirement to use private in-house registry and wanted to use node-sass package from that registry.

The problem is — node-sass internally uses postinstall script which tries to download precompiled sass binaries, and expect them from a various places https://github.com/sass/node-sass#binary-configuration-parameters one of which is a variable in .npmrc.

Further this variables are used like that:

What Happened Instead

Looks like npm ci doesn’t collect npmrc variables into process.env.npm_config_variable_name (as npm i do).

Reproduction Steps

If this behavior is not intended, then here is a repro steps:

npm init -y
npm i node-sass -D

# node-sass tries to cache downloaded binaries in this places, so clean them
rm -rf node_modules/
rm -rf ~/.npm/node-sass/

npm config set sass_binary_site http://path-to-local-registry-that-should-be-visible-in-npm-ci-log
npm ci

somewhere in logs we should see our URL from sass_binary_site ( http://path-to-local-registry-that-should-be-visible-in-npm-ci-log/v4.11.0/linux-x64-64_binding.node ).

But we saw the default one

> node-sass@4.11.0 install /home/denis/temp/node_modules/node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.11.0/linux-x64-64_binding.node

Details

If we run npm i - sass_binary_site variable will be taken into account.

Platform Info

$ npm --versions
{ 'npm-bug-repro': '1.0.0',
  npm: '6.9.0',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.13.0',
  openssl: '1.1.0i',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.36',
  zlib: '1.2.11' }
$ node -p process.platform
win32

We’re noticing similar issue starting with npm@6.6.0; we’ve the below property set in the global npmrc:

puppeteer_skip_chromium_download = true

to skip downloading chromium on puppeteer module installation, but npm ci isn’t respecting this.

1 Like

Also documented here: Cannot differentiate initiator in postinstall script

This also caught me out yesterday, after the official Docker image for node:10-alpine upgraded to v10.16.0 and npm v6.9.0. Having spent some time on it, is seems that all keys starting with npm_config_ are missing from process.env when you use npm ci.

This looks to have been introduced between v6.5.0 and v6.6.0-next.0.

We have also been caught out by this problem on a rather large scale.
Can we get any official information as to whether this is intended or a bug in the npm client?

1 Like

This will be fixed in the next release. https://github.com/npm/cli/commit/8b43c962498c8e2707527e4fca442d7a4fa51595

1 Like