np
np copied to clipboard
np hangs when installed as a local devDependency
[email protected]
seems to hang when run as a local devDependency.
Description
I've installed [email protected]
as a local devDependency.: yarn add -D np
. When running yarn np
(with or without flags or arguments) it hangs. After minutes of waiting I have to manually terminate it.
If I instead yarn remove np
and then use npx np
(same version of np
) it starts immediately.
Steps to reproduce
-
yarn add -D [email protected]
-
yarn np
- Process hangs
Expected behavior
I expect that running the local version of np
should work immediately, like the global or npx way.
Environment
np - 7.2.0 Node.js - 12.18.0 npm - 6.14.4 Git - git version 2.24.3 (Apple Git-128) OS - macOS Catalina 10.15.7 yarn - 1.22.10
I thought I had the same problem on 7.4.0
but after waiting a while it finally started the publishing process
i've seen it hang if isPackageNameAvailable never returns. the culprit is the is-name-taken
npm, which ships a massive uncompressed json file of packages every once in a while. if it's a few months out of date... it starts to get very slow at npmjs.
I can confirm this is the culprit. It's waiting to check if a package is available. I replaced the code in node_modules/np/source/cli-implementation.js
:
const availability = flags.publish ? await npm.isPackageNameAvailable(pkg) : {
isAvailable: false,
isUnknown: false,
};
With:
const availability = {
isAvailable: true,
isUnknown: false,
}
In my case it's possibly linked to the registry being a private one (using Verdaccio). I realize these may not be supported. But this did work in earlier versions of np
— maybe there was a recent change there.
i worked with the dev to fix the upstream issue. should hang less often, but still relies on network connection
I suggest adding a timeout there (e.g. reusing the pTimeout
function) just to make sure.