GMaiolo
GMaiolo

Reputation: 4628

CircleCI: $ npm test fails and doesn't find installed package

For some reason Circle is not able to use ts-mocha installed with npm install in a previos step in the building process.

It used to work, but for some reason it doesn't anymore out of a sudden.


This is the CircleCI build job result:

circle build job result

All tests are running fine locally:

local test run


This is the script in the package.json that I run with npm test:

"test": "env NODE_ENV=test ts-mocha ./test/**/*.spec.ts --timeout 10000"

The package version is "ts-mocha": "^6.0.0",

This is my CircleCI job configuration (which hasn't changed in a month):

jobs:
  build:
    docker:
      - image: circleci/node:10.13.0
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package-lock.json" }}
            - v1-dependencies-
      - run: npm install
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package-lock.json" }}
      - run: npm test
      - run: npx tsc


It seems that something broke from the Circle side, as there were no changes in the code.

Even though I tried rerunning old successful builds, they fail with this same error.

Things I tried:

Also tried using npx instead of relying on the previously installed ts-mocha package and this is the result:

enter image description here

Upvotes: 2

Views: 1585

Answers (1)

GMaiolo
GMaiolo

Reputation: 4628

I noticed that the CircleCI NODE_ENV environment variable was set to production, therefore any devDependencies were not getting installed (even with npm install --save, because it was already listed as a devDependency in the package.json).

I don't know when the environment variable was changed to that value, but the odd thing is that it started breaking from one day to another (although it should've been breaking since the moment that env variable was set) so it was extremely hard to debug, but it was a simple fix: changing the NODE_ENV environment variable in CircleCI to something different than production.

Upvotes: 1

Related Questions