Node.js npm install devDependencies

nodejs
npm
dependencies

#1

I am new to CIrcleCI. My build is failing with

> mocha test/*.js
sh: 1: mocha: not found

which I imagine is because the devDependencies specified in package.json are not being installed. I have tried setting NODE_ENV to development both in config.yml and in Settings > Environment Variables, to no avail.

My config.yml is

version: 2
jobs:
  build:
    docker:
      - image: node:8.0
    environment:
      - NODE_ENV: development
    steps:
      - checkout
      - run: npm test

What am I doing wrong? Thx.


#2

Answering my own question, I’ve found that it requires an explicit npm install:

version: 2
jobs:
  build:
    docker:
      - image: node:8.0
    environment:
      - NODE_ENV: development
    steps:
      - checkout
      - run: npm install
      - run: npm test

Now I have a different (‘chown’) error to track down…


#3

Extra info: the error I had (EINVAL: invalid argument, chown '/root/project/node_modules/.staging/acorn-globals-afaa2a6c') I found referenced in a number of CircleCI issues, the problem seems to be with the version of npm – this config.yml now works:

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:latest
    steps:
      - checkout
      - run: npm install
      - run: npm test

(currently it reports npm@5.3.0, node@v8.4.0).


#4