`npm ci` should fail if `node-gyp` fails

What I Wanted to Do

We run npm ci as a part of our CI pipeline. Recently we noticed, while Github had a hickup, that the npm ci-CI job was successful although it should have failed.

What Happened Instead

The node_modules was missing some files (because of the aforementioned situation), so all following CI-jobs failed.

Reproduction Steps

  • Run npm ci
  • wait, that Github is not available, so that npm is forced to build node-sass using node-gyp instead of just downloading the right binary
  • node-gyp should fail. (see log)
  • npm still proceedes and report the installation as a success

Details

We have the following job log:

> fsevents@1.2.4 install /data/node_modules/chokidar/node_modules/fsevents
> node install


> node-sass@4.11.0 install /data/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
Cannot download "https://github.com/sass/node-sass/releases/download/v4.11.0/linux-x64-64_binding.node": 

getaddrinfo ENOTFOUND github.com github.com:443

Hint: If github.com is not accessible in your location
      try setting a proxy via HTTP_PROXY, e.g. 

      export HTTP_PROXY=http://example.com:1234

or configure npm proxy via

      npm config set proxy http://example.com:8080

> node-sass@4.11.0 postinstall /data/node_modules/node-sass
> node scripts/build.js

Building: /usr/local/bin/node /data/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ '/usr/local/bin/node',
gyp verb cli   '/data/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library=' ]
gyp info using node-gyp@3.8.0
gyp info using node@10.15.3 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 /usr/bin/python2
gyp verb check python version `/usr/bin/python2 -c "import sys; print "2.7.13
gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
gyp verb get node dir no --target version specified, falling back to host node version: 10.15.3
gyp verb command install [ '10.15.3' ]
gyp verb install input version string "10.15.3"
gyp verb install installing version: 10.15.3
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 10.15.3
gyp verb ensuring nodedir is created /home/node/.node-gyp/10.15.3
gyp verb created nodedir /home/node/.node-gyp
gyp http GET https://nodejs.org/download/release/v10.15.3/node-v10.15.3-headers.tar.gz
gyp WARN install got an error, rolling back install
gyp verb command remove [ '10.15.3' ]
gyp verb remove using node-gyp dir: /home/node/.node-gyp
gyp verb remove removing target version: 10.15.3
gyp verb remove removing development files for version: 10.15.3
gyp ERR! configure error 
gyp ERR! stack Error: This is most likely not a problem with node-gyp or the package itself and
gyp ERR! stack is related to network connectivity. In most cases you are behind a proxy or have bad 
gyp ERR! stack network settings.
gyp ERR! stack     at Request.<anonymous> (/data/node_modules/node-gyp/lib/install.js:197:21)
gyp ERR! stack     at Request.emit (events.js:189:13)
gyp ERR! stack     at Request.onRequestError (/data/node_modules/request/request.js:881:8)
gyp ERR! stack     at ClientRequest.emit (events.js:189:13)
gyp ERR! stack     at TLSSocket.socketErrorListener (_http_client.js:392:9)
gyp ERR! stack     at TLSSocket.emit (events.js:189:13)
gyp ERR! stack     at emitErrorNT (internal/streams/destroy.js:82:8)
gyp ERR! stack     at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
gyp ERR! stack     at process._tickCallback (internal/process/next_tick.js:63:19)
gyp ERR! System Linux 4.5.0-0.bpo.2-amd64
gyp ERR! command "/usr/local/bin/node" "/data/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /data/node_modules/node-sass
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1

> fsevents@1.2.4 install /data/node_modules/fsevents
> node install

added 1204 packages in 15.811s

Platform Info

$ npm --versions
{ james: '0.0.0',
  npm: '6.9.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.3',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.51',
  zlib: '1.2.11' }
$ node -p process.platform
linux