zsh completions broken with npm 6.9.2 (macOS)

What I Wanted to Do

Tried opening a new zsh session.

What Happened Instead

Got stuck while loading.

Reproduction Steps

I just have

source <(npm completion)

in my .zshrc.

Details

I kind of figured out that it’s related to npm by launching zsh -v (verbose flag) and it stopped after the npm completions.

First was using zsh 5.7.1 (x86_64-apple-darwin18.2.0) (from brew) but also tried with /bin/zsh which is 5.3 (x86_64-apple-darwin18.0).

Platform Info

$ npm --versions
{ npm: '6.9.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.8.0',
  icu: '64.2',
  modules: '64',
  napi: '4',
  nghttp2: '1.34.0',
  node: '10.16.0',
  openssl: '1.1.1b',
  tz: '2019a',
  unicode: '12.1',
  uv: '1.28.0',
  v8: '6.8.275.32-node.52',
  zlib: '1.2.11' }

$ node -p process.platform
darwin

That’s strange that it broke in 6.9.2, since the shell code output hasn’t changed in about 7 years.

What happens if you output the completion script to a file and try to source it in verbose mode?

I also ran into this recently after not having the touched the MacOS machine at work for months. I don’t have this issue on my regular Ubuntu laptop.

I use source <(npm completion) in my .zshrc. This seems to hang indefinitely.

In short, it hangs indefinitely on this machine:

$ zsh --version
zsh 5.7.1 (x86_64-apple-darwin17.7.0)
$ node --version
v12.6.0
$ npm --version
6.10.1

But it works fine on this machine:

$ zsh --version
zsh 5.4.2 (x86_64-ubuntu-linux-gnu)
$ node --version
v10.16.0
$ npm --version
6.10.1

I can’t exactly say why but moving the

source <(npm completion)

line to the end of my .zshrc fixed it for me :man_shrugging:t2: (I had a few aliases, functions, etc after that).

Must have just been coincidence that it stopped working at the same time as updating npm…