Issue with npm install
Getting following error:
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
CircleCI config file:
version: 2
jobs:
build:
docker:
- image: circleci/node:latest
working_directory: ~/repo
steps:
- checkout
- run:
name: update-npm
command: 'sudo npm install -g npm@latest'
- restore_cache:
key: v0-dependencies-{{ checksum "package.json" }}
- run:
name: install-npm-packages
command: 'npm install'
- save_cache:
paths:
- ./node_modules
key: v0-dependencies-{{ checksum "package.json" }}
- run:
name: test
command: |
echo Running Tests
npm run test
- store_artifacts:
path: test-results.xml
prefix: tests
- store_artifacts:
path: coverage
prefix: coverage
- store_test_results:
path: test-results.xml
It depends on Node image version :
- no error: 4.*
Error: Cannot find module 'semver': >4
Same thing with offical Node images.
This is an NPM issue : https://github.com/npm/npm/issues/16807, https://github.com/npm/npm/issues/15558, https://github.com/nodejs/docker-node/issues/449
Simple workaround is to use latest Node image with latest NPM and not update NPM manually.
Are you sure you have semver in your package.json?
This is what worked for me for the update-npm step in config.yml:
yarn global add npm@latest
This is what worked for me for the
update-npmstep inconfig.yml:yarn global add npm@latest
I have used your command but npm version is not latest, I added this step in circle to verify. - run: name: Check npm and node version command: | node --version npm --version
The output was 5.5.1. Currently the latest version is 6.4.1.