npm / npm/cli

[BUG] npx is too slow for already cached package with specific version requested

Open
#7,295 6 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement perf Priority 2
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

I'm npxing a specific version of a package that's already been npxed before.
There is a long delay (at least 3 seconds) even before it fetches the package information from the registry (which, why is this necessary for a specific version that's already installed?) and using --ddd doesn't provide any information why the delay is happening.

$ npx --ddd type-annotation-to-json-schema@1.0.0
npm verb cli /Users/andy/.nvm/versions/node/v21.7.1/bin/node /Users/andy/.nvm/versions/node/v21.7.1/lib/node_modules/npm/bin/npm-cli.js
npm info using npm@10.5.0
npm info using node@v21.7.1
npm verb title npm exec type-annotation-to-json-schema@1.0.0
npm verb argv "exec" "--loglevel" "silly" "--" "type-annotation-to-json-schema@1.0.0"
npm verb logfile logs-max:10 dir:/Users/andy/.npm/_logs/2024-03-18T14_33_12_835Z-
npm verb logfile /Users/andy/.npm/_logs/2024-03-18T14_33_12_835Z-debug-0.log
npm sill logfile start cleaning logs, removing 7 files
npm sill logfile done cleaning log files
**...LONG MYSTERIOUS DELAY...**
npm http fetch GET 200 https://registry.npmjs.org/type-annotation-to-json-schema 460ms (cache revalidated)
type-annotation-to-json-schema <file> <identifier>
Expected Behavior

npx should be virtually instantaneous for a specific version of a package that's already installed. I expected it to not fetch anything from the registry if the package is already in cache.

Steps To Reproduce
  1. Run npx --ddd gen-typed-validators@1.0.0 several times
  2. Observe long delay before it finishes running even after the first time
Environment
  • npm: 10.5.0
  • Node.js: 21.7.1
  • OS Name: macOS 14.4
  • System Model Name: Macbook Pro
  • npm config:
; "user" config from /Users/andy/.npmrc

//registry.npmjs.org/:_authToken = (protected) 
hoist = true 
registry = "https://registry.npmjs.org/" 

; node bin location = /Users/andy/.nvm/versions/node/v21.7.1/bin/node
; node version = v21.7.1
; npm local prefix = /Users/andy/gh/clarity
; npm version = 10.5.0
; cwd = /Users/andy/gh/clarity
; HOME = /Users/andy
; Run `npm config ls -l` to show all defaults.

; "publishConfig" from /Users/andy/gh/clarity/package.json
; This set of config values will be used at publish-time.

access = "restricted"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the repeated npx --ddd gen-typed-validators@1.0.0 run and tracing the npm exec path around the delay and registry request. Done means a cached, explicitly requested package version runs without the unnecessary delay or registry fetch, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.