npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

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

Noticed something weird, I wonder if anybody has seen anything similar: I have a node module that depends on another node module, not through but through a git+ 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

`-- node_modules
    `-- secondmodule
        |-- package.json
        `-- dist
            |-- ...

while in the root-in-docker environment we have

`-- node_modules
    `-- secondmodule
        `-- 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: '',
  zlib: '1.2.11' }

npm does behave specially when run as root:

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.

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.

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.

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


RUN npm ci --unsafe-perm=true

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