np 5.1 instantly crashes on macOS

Created on 16 Sep 2019  ·  7Comments  ·  Source: sindresorhus/np

Description

When I run np 5.1.0 it instantly crashes. The error contains something about Cellar so I assume it's something strange with homebrew. But whatever the case is, it should just not crash.
Installing [email protected] again it runs just fine.

I assume the root cause of the error is within is-installed-globally or global-dirs but that shouldn't excuse np just being useless and crash instantly.

My global node_modules path is /usr/local/lib/node_modules and not /usr/local/Cellar/node/12.10.0/lib/node_modules.

Error message:

$ np
fs.js:130
    throw err;
    ^

Error: ENOENT: no such file or directory, lstat '/usr/local/Cellar/node/12.10.0/lib/node_modules'
    at Object.realpathSync (fs.js:1540:7)
    at Object.<anonymous> (/usr/local/lib/node_modules/np/node_modules/is-installed-globally/index.js:8:29)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (internal/modules/cjs/helpers.js:68:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/np/source/config.js:3:29)
    at Module._compile (internal/modules/cjs/loader.js:936:30) {
  errno: -2,
  syscall: 'lstat',
  code: 'ENOENT',
  path: '/usr/local/Cellar/node/12.10.0/lib/node_modules'
}

Steps to reproduce

  1. Install np globally: npm i -g np@latest
  2. Use np with any command

Expected behavior


np 5.1 should work like 5.0 does.

Environment

$ npm ls -g --depth=0 np
/usr/local/lib
└── [email protected] 

$ npm -v
6.11.3

$ node -v
v12.10.0

$ git --version
git version 2.23.0

OS - macOS Mojave 10.14.6

Most helpful comment

Here is my stacktrace (if that helps):

2019-09-18 at 19 31

5.1.0 crashes
5.0.3 works

All 7 comments

had to do a

npm install --global [email protected]

Also experiencing issues with 5.1, such as yarn publish not working, but using --no-yarn works. May be related to https://github.com/sindresorhus/np/issues/451.

I assume the root cause of the error is within is-installed-globally or global-dirs but that shouldn't excuse np just being useless and crash instantly.

np can't really continue without knowing whether it's run globally or locally as it needs to pick the correct np config. So crashing hard here is correct, although it could have used a better error message.

Seem like the issue was introduced in https://github.com/sindresorhus/is-installed-globally/commit/b898cd4fa3cb40eaf1035dbf88d87e28370cfe50

// @NeekSandhu

Here is my stacktrace (if that helps):

2019-09-18 at 19 31

5.1.0 crashes
5.0.3 works

so..... what needs to happen to fix this?

Update, I figured it out. yarn publish 🤷‍♂

I'm using npx [email protected] as workaround

Was this page helpful?
0 / 5 - 0 ratings