Docker-node: Updating npm fails

Created on 6 Jul 2017  路  3Comments  路  Source: nodejs/docker-node

Self-updating npm to the latest fails

$ docker run -it node:8 bash -xc "npm install npm@latest -g; npm --version"

+ npm install npm@latest -g
npm info it worked if it ends with ok
...
npm info ok

+ npm --version
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)

Most helpful comment

Closing as this is an npm issue, not an issue with these images. See linked thread for workarounds. This is the easiest I've come up with:

FROM node:8

RUN yarn global add npm

RUN npm --version

All 3 comments

This is a known issue with npm 5.

npm/npm#16807

Closing as this is an npm issue, not an issue with these images. See linked thread for workarounds. This is the easiest I've come up with:

FROM node:8

RUN yarn global add npm

RUN npm --version

As suggested by @iamdoron elsewhere, this works on older images without yarn:

FROM mhart/alpine-node:6.11.1
RUN npm i -g npm3 && npm3 -g uninstall npm
RUN npm3 i -g npm@5
Was this page helpful?
0 / 5 - 0 ratings