Attempting to install npm packages in Docker results in an error like:
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "-g" "install" "yuglify"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! path /usr/local/lib/node_modules/yuglify
npm ERR! EXDEV: cross-device link not permitted, rename '/usr/local/lib/node_modules/yuglify' -> '/usr/local/lib/node_modules/.yuglify.DELETE'
My Dockerfile looks like:
FROM ubuntu:18.04
ENV PYTHONUNBUFFERED 1
USER root
RUN apt-get -yq update && apt-get install -yq npm
CMD npm -g install yuglify
Strangely, if I run the npm install command twice, the second call works.
Seeing this surface again with v7 on docker images (v7.0.3)
Seems it's a regression of https://github.com/npm/npm/pull/15901
Reproduction:
docker run --rm mhart/alpine-node:15 npm install -g npm@7
In npm 7, "the entire Installer class is moved into @npmcli/arborist.": https://github.com/npm/cli/blob/latest/CHANGELOG.md#v700-beta0-2020-08-04
I believe the issue might be in there. It appears that it tries to rename instead of move now: https://github.com/npm/arborist/blob/main/lib/arborist/reify.js#L254
Which looks like a regression of that old PR you linked: https://github.com/npm/npm/pull/15901
That PR replaced all renames with moves ("install: Use EXDEV aware move instead of rename")
Most helpful comment
In npm 7, "the entire Installer class is moved into @npmcli/arborist.": https://github.com/npm/cli/blob/latest/CHANGELOG.md#v700-beta0-2020-08-04
I believe the issue might be in there. It appears that it tries to rename instead of move now: https://github.com/npm/arborist/blob/main/lib/arborist/reify.js#L254
Which looks like a regression of that old PR you linked: https://github.com/npm/npm/pull/15901
That PR replaced all renames with moves ("install: Use EXDEV aware move instead of rename")