Node.js 12 job fails on npm ci (Cannot read property 'toString' of null)

I have a project that runs tests on Node.js 12, it has been erroring on Travis since the start of this week.

The error is npm ERR! Cannot read property 'toString' of null when running npm ci
I have been unable to reproduce this locally and, without access to the npm debug log, cannot debug this further.

An example of an errored build: https://travis-ci.org/Ionaru/steve/jobs/548565831

My travis config:

jobs:
    include:
        - stage: Test
          language: node_js
          node_js: '12'

        - stage: Deploy
          language: bash
          script: skip
          deploy:
              - provider: script
                script: bash deploy.sh Steve_Deploy $API_TOKEN
                on:
                    branch: master
                    repo: Ionaru/steve

env:
    global:
        - secure: <SNIP>
        - secure: <SNIP>

Why are these builds failing and how can I prevent it in the future?

Probably because you have something cached on your machine.

I suggest testing on a fresh machine, and examine the commit that introduced the failure.

Also, you may want to dump the error log /home/travis/.npm/_logs/*-debug.log

I’ve removed the NPM cache and retried the install, it still succeeds locally.

How do I dump the npm debug file from Travis? An after_failure phase did not get triggered.

after_failure does not fire because the error is happening in install, which results in an error, which is different from a failure. I suggest overriding install with npm cli || cat … for now.

Coincidentally, I advise against splitting your deployment to a separate job if you have only one Test job to run. It is much simpler and much more efficient to rely on your single Test job to run the test and deploy upon success. If you split, you will have to pay for the extra time for the second VM to start and set up the environment before it can deploy.