Issue 1:
Before Opening Please...

Search for an existing/duplicate RRFC which might be relevant to your RRFC

There is one RFC about logging: using STDERR for errors instead of STDOUT. This is unrelated.

Motivation ("The Why")

Currently some CI providers, specifically GitLab, restrict job artifacts to being relative to the repository. Presumably, this stops you from uploading runner files that may have dirty-state left from previous runs in non-containerized workflows. Specifically the GitLab documents say,

The paths keyword determines which files to add to the job artifacts. All paths to files and directories are relative to the repository where the job was created.

This effectively means NPM logs on error can not be captured as job artifacts.

Example

How

Current Behaviour

What I would like to do is something like this (ignore the actual error)

$ npx ng e2e
npm ERR! could not determine executable to run
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-11-22T17_24_50_085Z-debug.lo

Then I want to upload /root/.npm/_logs/2021-11-22T17_24_50_085Z-debug.log as a job artifact.

This is not currently possible

Desired Behaviour

In light of GitLab not permitting global files to be uploaded as job artifacts I would like an option to set the log file,

npx [--log <LOCATION>] ng e2e

Such that LOCATION could be relative to the cwd.

Then I could do,

$ npx --log "./.npm/_logs/" ng e2e

And set ./.npm/_logs/* as my artifacts to upload to GitLab.

References

npm/npm#1548

npm/npm#5252

npm/npm#6744 (exact comment that explains this issue's importance to CI: I am not alone)

https://stackoverflow.com/questions/21624030/change-npm-debug-log-location/23456148

Issue 2:
EDIT

See #3847 (comment) for minimum reproduction case. --@wraithgar

Is there an existing issue for this?

I have searched the existing issues

Current Behavior

Running npm install --workspace=<workspace> is resulting in npm exiting with an errorcode and the following stack trace:

290 timing command:install Completed in 2473ms
291 verbose stack TypeError: Cannot set property 'dev' of null
291 verbose stack at calcDepFlagsStep (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:34:21)
291 verbose stack at visit (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:12:20)
291 verbose stack at visitNode (/usr/local/lib/node_modules/npm/node_modules/treeverse/lib/depth-descent.js:57:25)
291 verbose stack at next (/usr/local/lib/node_modules/npm/node_modules/treeverse/lib/depth-descent.js:44:19)
291 verbose stack at depth (/usr/local/lib/node_modules/npm/node_modules/treeverse/lib/depth-descent.js:82:10)
291 verbose stack at depth (/usr/local/lib/node_modules/npm/node_modules/treeverse/lib/depth.js:27:12)
291 verbose stack at calcDepFlags (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:10:15)
291 verbose stack at Arborist.[copyIdealToActual] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:1375:7)
291 verbose stack at Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:151:35)
291 verbose stack at async Install.install (/usr/local/lib/node_modules/npm/lib/install.js:170:5)
292 verbose cwd /usr/src
293 verbose Linux 5.10.47-linuxkit
294 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--workspace=scheduler"
295 verbose node v14.16.1
296 verbose npm v7.24.2
297 error Cannot set property 'dev' of null
298 verbose exit 1

Dockerfile for container I'm running the command in:

FROM node:14.16.1
RUN npm install -g npm@7.24.2

RUN mkdir -p /usr/src/
WORKDIR /usr/src

COPY ./package.json /usr/src/
COPY ./scheduler/package.json /usr/src/scheduler/
RUN npm install --workspace=scheduler

node_modules seem to successfully install but npm exits with an error code

Expected Behavior

npm install completes without raising an error

Steps To Reproduce

Setup an npm project with workspaces

Create a docker container according to the above specifications, with one of the commands attempting to run npm install for a specific workspace

Attempt to build the container

npm installs node_modules successfully but exits with error

Environment

OS: Debian GNU/Linux 9 (stretch)

Node: 14.16.1

npm: 7.24.2