<p dir="auto">Hello,</p>
<p dir="auto">when I run the following testcase in the dockerfile with npm 7.0.6 it fails with:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="npm ERR! Cannot read property 'once' of undefined"><pre class="notranslate"><code class="notranslate">npm ERR! Cannot read property 'once' of undefined
</code></pre></div>
<p dir="auto">Running it with 7.0.5 works as expected.</p>
<p dir="auto">Dockerfile:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="FROM ubuntu:20.04

# silence debconf
ENV DEBIAN_FRONTEND=noninteractive

# update base packages
RUN apt-get update &amp;&amp; apt-get upgrade -y

# install nodejs
WORKDIR /opt
RUN apt-get install -y tar wget xz-utils
RUN wget --no-check-certificate https://nodejs.org/download/release/latest-v12.x/node-v12.19.0-linux-x64.tar.xz \
    &amp;&amp; tar -axvf node-v12.19.0-linux-x64.tar.xz
RUN ln -s /opt/node-v12.19.0-linux-x64/bin/* /usr/local/bin/

# upgrade npm
RUN npm install npm@7.0.6 -g # CVE-2020-15095 / GHSA-xgh6-85xh-479p
RUN npm --version

# run testcase
WORKDIR /testcase
ADD package.json .
RUN npm run testcase"><pre class="notranslate"><code class="notranslate">FROM ubuntu:20.04

# silence debconf
ENV DEBIAN_FRONTEND=noninteractive

# update base packages
RUN apt-get update &amp;&amp; apt-get upgrade -y

# install nodejs
WORKDIR /opt
RUN apt-get install -y tar wget xz-utils
RUN wget --no-check-certificate https://nodejs.org/download/release/latest-v12.x/node-v12.19.0-linux-x64.tar.xz \
    &amp;&amp; tar -axvf node-v12.19.0-linux-x64.tar.xz
RUN ln -s /opt/node-v12.19.0-linux-x64/bin/* /usr/local/bin/

# upgrade npm
RUN npm install npm@7.0.6 -g # CVE-2020-15095 / GHSA-xgh6-85xh-479p
RUN npm --version

# run testcase
WORKDIR /testcase
ADD package.json .
RUN npm run testcase
</code></pre></div>
<p dir="auto">package.json:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
    &quot;name&quot;: &quot;testcase&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;dummy test case&quot;,
    &quot;scripts&quot;: {
        &quot;testcase&quot;: &quot;/bin/true&quot;
    }
}"><pre class="notranslate"><code class="notranslate">{
    "name": "testcase",
    "version": "1.0.0",
    "description": "dummy test case",
    "scripts": {
        "testcase": "/bin/true"
    }
}
</code></pre></div>
<p dir="auto">Could you please take a look?</p>
<h1 dir="auto">What / Why</h1>
<p dir="auto">This code assumes that <code class="notranslate">add</code> is only ever called with an object with a <code class="notranslate">once</code> method:</p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/npm/run-script/blob/1c7bbcdaf5ae2a8d6a0762063505746fe20d577c/lib/signal-manager.js#L31-L36">run-script/lib/signal-manager.js</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 31 to 36
      in
      <a data-pjax="true" class="commit-tease-sha" href="/npm/run-script/commit/1c7bbcdaf5ae2a8d6a0762063505746fe20d577c">1c7bbcd</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L31" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="31"></td>
          <td id="LC31" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">const</span> <span class="pl-en">add</span> <span class="pl-c1">=</span> <span class="pl-s1">proc</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L32" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="32"></td>
          <td id="LC32" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-s1">runningProcs</span><span class="pl-kos">.</span><span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s1">proc</span><span class="pl-kos">)</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L33" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="33"></td>
          <td id="LC33" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-s1">handlersInstalled</span><span class="pl-kos">)</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L34" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="34"></td>
          <td id="LC34" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-en">setupListeners</span><span class="pl-kos">(</span><span class="pl-kos">)</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L35" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="35"></td>
          <td id="LC35" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">  </td>
        </tr>

        <tr class="border-0">
          <td id="L36" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="36"></td>
          <td id="LC36" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-s1">proc</span><span class="pl-kos">.</span><span class="pl-en">once</span><span class="pl-kos">(</span><span class="pl-s">'exit'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">{</span> code <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">In fact, <code class="notranslate">add</code> is called with <code class="notranslate">undefined</code> in a Docker container when running any script. (I'm not sure what about the Docker environment causes this.) See repro instructions below.</p>
<h2 dir="auto">When</h2>
<p dir="auto">Repros consistently.</p>
<h2 dir="auto">Where</h2>
<ul dir="auto">
<li>n/a</li>
</ul>
<h2 dir="auto">How</h2>
<ul dir="auto">
<li>n/a</li>
</ul>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">When running any script, npm raises the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="23 verbose stack TypeError: Cannot read property 'once' of undefined
23 verbose stack     at Object.add (/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/signal-manager.js:36:8)
23 verbose stack     at runScriptPkg (/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script-pkg.js:63:19)
23 verbose stack     at runScript (/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script.js:8:16)
23 verbose stack     at runScript (/usr/local/lib/node_modules/npm/lib/run-script.js:77:11)"><pre class="notranslate"><code class="notranslate">23 verbose stack TypeError: Cannot read property 'once' of undefined
23 verbose stack     at Object.add (/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/signal-manager.js:36:8)
23 verbose stack     at runScriptPkg (/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script-pkg.js:63:19)
23 verbose stack     at runScript (/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script.js:8:16)
23 verbose stack     at runScript (/usr/local/lib/node_modules/npm/lib/run-script.js:77:11)
</code></pre></div>
<h3 dir="auto">Steps to Reproduce</h3>
<p dir="auto">Create a <code class="notranslate">Dockerfile</code> containing:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="FROM node:14.14

RUN npm install --global npm@7.0.6

WORKDIR /app

RUN npm init -y
RUN npm test || exit 0
RUN cat /root/.npm/_logs/*.log"><pre class="notranslate"><code class="notranslate">FROM node:14.14

RUN npm install --global npm@7.0.6

WORKDIR /app

RUN npm init -y
RUN npm test || exit 0
RUN cat /root/.npm/_logs/*.log
</code></pre></div>
<p dir="auto">Then, run <code class="notranslate">docker build .</code>.</p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">An error should not be raised.</p>
<h2 dir="auto">Who</h2>

<ul dir="auto">
<li><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/isaacs/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/isaacs">@isaacs</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/nlf/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/nlf">@nlf</a></li>
</ul>
<h2 dir="auto">References</h2>

<ul dir="auto">
<li>n/a</li>
</ul>