np icon indicating copy to clipboard operation
np copied to clipboard

np hangs when installed as a local devDependency

Open mshwery opened this issue 3 years ago • 1 comments

[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

  1. yarn add -D [email protected]
  2. yarn np
  3. 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

mshwery avatar Jan 15 '21 17:01 mshwery

I thought I had the same problem on 7.4.0 but after waiting a while it finally started the publishing process

cdimitroulas avatar Feb 26 '21 18:02 cdimitroulas

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.

earonesty avatar Jun 14 '23 16:06 earonesty

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.

slhck avatar Jul 26 '23 11:07 slhck

i worked with the dev to fix the upstream issue. should hang less often, but still relies on network connection

earonesty avatar Jul 26 '23 22:07 earonesty

I suggest adding a timeout there (e.g. reusing the pTimeout function) just to make sure.

slhck avatar Jul 27 '23 06:07 slhck