Npm install error

build-image
nodejs
npm

#1

Using the below config I am trying to run a simple test/build however CircleCI is breaking on the npm install step with the error (beneath the config).

version: 2
jobs:
  build:
    working_directory: ~/test-project
    docker:
      - image: circleci/node:latest
    steps:
    - checkout
    - run:
        name: update-npm
        command: 'sudo npm install -g npm@latest'
    - run:
        name: install-npm
        command: cd ~/test-project/App && pwd && npm install
    - run:
        name: test
        command: cd ~/test-project/App && npm test
    - run:
        name: test
        command: cd ~/test-project/App && npm run build
workflows:
  version: 2
  test_and_build:
    jobs:
      - build

The error:

#!/bin/bash -eo pipefail
cd ~/test-project/App && pwd && npm install
/home/circleci/test-project/App
module.js:487
    throw err;
    ^

Error: Cannot find module 'semver'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/unsupported.js:2:14)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
Exited with code 1

As far as I’m aware I have set everything up correctly, but it seems that the build server does not have npm installed, or at least on $PATH. I have confirmed this by ssh-ing into the server.

Does anyone know how to fix this? Let me know if I need to provide more information.


#2

I suffered from the same problem, and it seemed like the following command caused the problem.

sudo npm install -g npm@latest

I looked for a solution and tried a couple of ways described in the following link, but they didn’t work.

So I just gave up to update npm by executing the command, and started using “node:latest-browsers” instead. As of now, we can use npm@5.0.3 with node:latest-browsers (Or maybe node:latest would be fine too)


#3