<h1 dir="auto">Before Opening Please...</h1>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Search for an existing/duplicate RRFC which might be relevant to your RRFC</li>
</ul>
<p dir="auto"><a href="npm/cli#4724">There is one RFC about logging: using STDERR for errors instead of STDOUT. This is unrelated.</a></p>
<h2 dir="auto">Motivation ("The Why")</h2>
<p dir="auto">Currently some CI providers, <a href="https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html" rel="nofollow">specifically GitLab</a>, 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,</p>
<blockquote>
<p dir="auto">The <code class="notranslate">paths</code> keyword determines which files to add to the job artifacts. <strong>All paths to files and directories are relative</strong> to the repository where the job was created.</p>
</blockquote>
<p dir="auto">This effectively means NPM logs on error can not be captured as job artifacts.</p>
<h3 dir="auto">Example</h3>
<h3 dir="auto">How</h3>
<h4 dir="auto">Current Behaviour</h4>
<p dir="auto">What I would like to do is something like this (ignore the actual error)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ 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"><pre class="notranslate"><code class="notranslate">$ 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
</code></pre></div>
<p dir="auto">Then I want to upload <code class="notranslate">/root/.npm/_logs/2021-11-22T17_24_50_085Z-debug.log</code> as a job artifact.</p>
<p dir="auto"><strong>This is not currently possible</strong></p>
<h4 dir="auto">Desired Behaviour</h4>
<p dir="auto">In light of GitLab not permitting global files to be uploaded as job artifacts I would like an option to set the log file,</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="npx [--log &lt;LOCATION&gt;] ng e2e"><pre class="notranslate">npx [--log <span class="pl-k">&lt;</span>LOCATION<span class="pl-k">&gt;</span>] ng e2e</pre></div>
<p dir="auto">Such that <code class="notranslate">LOCATION</code> could be relative to the cwd.</p>
<p dir="auto">Then I could do,</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ npx --log &quot;./.npm/_logs/&quot; ng e2e"><pre class="notranslate"><code class="notranslate">$ npx --log "./.npm/_logs/" ng e2e
</code></pre></div>
<p dir="auto">And set <code class="notranslate">./.npm/_logs/*</code> as my artifacts to upload to GitLab.</p>
<h3 dir="auto">References</h3>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1898387" data-permission-text="Title is private" data-url="https://github.com/npm/npm/issues/1548" data-hovercard-type="issue" data-hovercard-url="/npm/npm/issues/1548/hovercard" href="https://github.com/npm/npm/issues/1548">npm/npm#1548</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="33263168" data-permission-text="Title is private" data-url="https://github.com/npm/npm/issues/5252" data-hovercard-type="pull_request" data-hovercard-url="/npm/npm/pull/5252/hovercard" href="https://github.com/npm/npm/pull/5252">npm/npm#5252</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="49460729" data-permission-text="Title is private" data-url="https://github.com/npm/npm/issues/6744" data-hovercard-type="pull_request" data-hovercard-url="/npm/npm/pull/6744/hovercard" href="https://github.com/npm/npm/pull/6744">npm/npm#6744</a> (exact comment that explains this issue's importance to CI: I am not alone)</li>
<li><a href="https://stackoverflow.com/questions/21624030/change-npm-debug-log-location/23456148" rel="nofollow">https://stackoverflow.com/questions/21624030/change-npm-debug-log-location/23456148</a></li>
</ul>
<h3 dir="auto">EDIT</h3>
<p dir="auto">See <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1019460977" data-permission-text="Title is private" data-url="https://github.com/npm/cli/issues/3847" data-hovercard-type="issue" data-hovercard-url="/npm/cli/issues/3847/hovercard?comment_id=1219533329&amp;comment_type=issue_comment" href="https://github.com/npm/cli/issues/3847#issuecomment-1219533329">#3847 (comment)</a> for minimum reproduction case. --<a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/wraithgar/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/wraithgar">@wraithgar</a></p>
<hr>
<h3 dir="auto">Is there an existing issue for this?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the existing issues</li>
</ul>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">Running <code class="notranslate">npm install --workspace=&lt;workspace&gt;</code> is resulting in npm exiting with an errorcode and the following stack trace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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 &quot;/usr/local/bin/node&quot; &quot;/usr/local/bin/npm&quot; &quot;install&quot; &quot;--workspace=scheduler&quot;
295 verbose node v14.16.1
296 verbose npm  v7.24.2
297 error Cannot set property 'dev' of null
298 verbose exit 1"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<p dir="auto">Dockerfile for container I'm running the command in:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<p dir="auto">node_modules seem to successfully install but npm exits with an error code</p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">npm install completes without raising an error</p>
<h3 dir="auto">Steps To Reproduce</h3>
<ol dir="auto">
<li>Setup an npm project with workspaces</li>
<li>Create a docker container according to the above specifications, with one of the commands attempting to run npm install for a specific workspace</li>
<li>Attempt to build the container</li>
<li>npm installs node_modules successfully but exits with error</li>
</ol>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>OS: Debian GNU/Linux 9 (stretch)</li>
<li>Node: 14.16.1</li>
<li>npm: 7.24.2</li>
</ul>