npm ci not running prepare for git dependencies when run as root in docker


(Ilkka Poutanen) #1

Noticed something weird, I wonder if anybody has seen anything similar: I have a node module that depends on another node module, not through npmjs.com but through a git+https://github.com URL. That second module has a build step, run in its prepare script. The second module’s files array is set to ["dist"].

When doing npm ci in the first module in Windows, in Ubuntu on Windows and almost any other conceivable environment, everything works and the second module gets installed, except! If npm ci is run as root in a docker container, the dist folder “disappears” or never gets created or whatever. In other words, after npm ci in a working environment, we have

firstmodule
`-- node_modules
    `-- secondmodule
        |-- README.md
        |-- package.json
        `-- dist
            |-- ...

while in the root-in-docker environment we have

firstmodule
`-- node_modules
    `-- secondmodule
        |-- README.md
        `-- package.json

This seems pretty similar in impact to Using npm ci does not run prepare script for git modules and I wonder if @jrobeson was working in a similar environment to mine when encountering this issue in September?

This is my npm --versions output, identical for both a working (nodesource official node 10.15.0 in Ubuntu on Windows) and a non-working (same node, Ubuntu 18 in a Docker container as root) environment:

{ npm: '6.4.1',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.15.0',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.45',
  zlib: '1.2.11' }

(John Gee) #2

npm does behave specially when run as root:
https://docs.npmjs.com/misc/scripts#user

A quick check if this is relevant to your problem might be to try adding --unsafe-perm to the install and see if it changes the behaviour.


(Ilkka Poutanen) #3

Thanks, hadn’t noticed that bit before! Looks like --unsafe-perm doesn’t help here though, the dist folder doesn’t appear using either npm --unsafe-perm ci or npm --unsafe-perm install.


(Tim Beyer) #4

I am experiencing the same problem with the results of the prepare script not showing up inside of a docker build. I have tried --unsafe-perm and I have tried running everything as a separate user in a separate group so that we aren’t dealing with root here.

Logging seems to indicate that it at least attempts to run the prepare scripts, and no errors were logged from that process.

In the end whatever I do, the resulting files from the build triggered in the prepare script are gone.
When I run this outside of docker, everything works fine though.


(Tim Beyer) #5

Turns out it actually does work just fine with

RUN npm config set unsafe-perm true && npm ci

but not with

RUN npm ci --unsafe-perm

or

RUN npm ci --unsafe-perm=true

(Ilkka Poutanen) #6

Awesome, that seems to have worked. Naturally, I already rewrote the Dockerfile to do everything as a regular user, though :slight_smile:


(system) #7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.