`npx envinfo --preset jest` fails on Windows with a stack trace

cli
help-wanted
good-first-patch
priority:low
triaged

(Kyle Getz) #1

What I Wanted to Do

Run npx envinfo --preset jest on Windows

What Happened Instead

$ npx envinfo --preset jest
Error: EPERM: operation not permitted, mkdir '<redacted>'
TypeError: Cannot read property 'get' of undefined
    at errorHandler (C:\Program Files\Node.js\node_modules\npm\lib\utils\error-handler.js:205:18)
    at C:\Program Files\Node.js\node_modules\npm\bin\npm-cli.js:78:20
    at cb (C:\Program Files\Node.js\node_modules\npm\lib\npm.js:228:22)
    at C:\Program Files\Node.js\node_modules\npm\lib\npm.js:266:24
    at C:\Program Files\Node.js\node_modules\npm\lib\config\core.js:83:7
    at Array.forEach (<anonymous>)
    at C:\Program Files\Node.js\node_modules\npm\lib\config\core.js:82:13
    at f (C:\Program Files\Node.js\node_modules\npm\node_modules\once\once.js:25:25)
    at afterExtras (C:\Program Files\Node.js\node_modules\npm\lib\config\core.js:173:20)
    at C:\Program Files\Node.js\node_modules\npm\node_modules\mkdirp\index.js:47:53
C:\Program Files\Node.js\node_modules\npm\lib\utils\error-handler.js:205
  if (npm.config.get('json')) {
                 ^

TypeError: Cannot read property 'get' of undefined
    at process.errorHandler (C:\Program Files\Node.js\node_modules\npm\lib\utils\error-handler.js:205:18)
    at emitOne (events.js:116:13)
    at process.emit (events.js:211:7)
    at process._fatalException (bootstrap_node.js:378:26)
Install for prefix@latest failed with code 7
Error: EPERM: operation not permitted, mkdir '<redacted>'
TypeError: Cannot read property 'get' of undefined
    at errorHandler (C:\Program Files\Node.js\node_modules\npm\lib\utils\error-handler.js:205:18)
    at C:\Program Files\Node.js\node_modules\npm\bin\npm-cli.js:78:20
    at cb (C:\Program Files\Node.js\node_modules\npm\lib\npm.js:228:22)
    at C:\Program Files\Node.js\node_modules\npm\lib\npm.js:266:24
    at C:\Program Files\Node.js\node_modules\npm\lib\config\core.js:83:7
    at Array.forEach (<anonymous>)
    at C:\Program Files\Node.js\node_modules\npm\lib\config\core.js:82:13
    at f (C:\Program Files\Node.js\node_modules\npm\node_modules\once\once.js:25:25)
    at afterExtras (C:\Program Files\Node.js\node_modules\npm\lib\config\core.js:173:20)
    at C:\Program Files\Node.js\node_modules\npm\node_modules\mkdirp\index.js:47:53
C:\Program Files\Node.js\node_modules\npm\lib\utils\error-handler.js:205
  if (npm.config.get('json')) {
                 ^

TypeError: Cannot read property 'get' of undefined
    at process.errorHandler (C:\Program Files\Node.js\node_modules\npm\lib\utils\error-handler.js:205:18)
    at emitOne (events.js:116:13)
    at process.emit (events.js:211:7)
    at process._fatalException (bootstrap_node.js:378:26)
Install for envinfo@latest failed with code 7

Reproduction Steps

Run npx envinfo --preset jest on Windows 10

Platform Info

$ npm --versions
{ npm: '6.4.1',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.32.0',
  node: '8.11.4',
  openssl: '1.0.2p',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.54',
  zlib: '1.2.11' }

$ node -p process.platform
win32

Release: npm@6.6.0-next.0
(Kat Marchán) #2

The error here is being hidden by a different bug. That means the error is happening pretty early in npm’s execution – the surface bug is accessing npm.config when it’s not actually defined. It’s a pretty straightforward patch to make that line if (npm.config && npm.config.get('json')) { ... } instead. I think you should do it yourself on your local npm and retry the npx command, since that’ll give you a better stack trace and we can figure out the underlying cause.

Either way, I’d appreciate a PR for that surface bug. :slight_smile:


(Kyle Getz) #3

It would probably be faster for you guys to fix the surface bug. I don’t work on npm and in fact my team uses yarn for everything. I only noticed this because the output of that npx command was requested by the author of another project.


(Beni Von Cheni) #4

Hi @zkat, really HAPPY to try out a patch in this PR. :wink: