[FEATURE] Offline cache
Opened this issue · 4 comments
What / Why
Running npx
is easier than npm install --global
but when I'm offline it doesn't work. I'd love to have a cache!
When
Always.
Where
- n/a
How
Just use a cache if it's available.
Current Behavior
npx only works when you're online
Expected Behavior
npx should work when I'm offline as long as I've run the command once while being online (because cache)
Who
- n/a
References
- n/a
I saw @zkat's comment here that it's equivalent to npm -g i foo && foo <args>
, but unfortunately npm -g i
comes with EACCESS errors by default and requires multiple workaround steps.
I want to tell people "run my program with npx foo
" and have that Just Work. I don't want to say:
run my program with
mkdir -p ~/.npm-global npm config set prefix '~/.npm-global' source ~/.profile npm i -g foo fooBtw if you're running zsh, replace
~/.profile
with~/.zprofile
. Also if you already have a global npm prefix, sorry, just runnpm i -g foo
.
It requires running sudo npm install -g
, is all.
Yes, that's a workaround, but it has security/usability trade-offs and directly conflicts with the documentation. I love that npx
doesn't run arbitrary lifecycle scripts as root and would prefer to avoid sudo
as a solution.
Another use case for this feature request:
Since you are using npx
to run an infrequently used tool, often I will need to run --help
first or sometimes I might get a flag wrong here and there. Usually the lifecycle in this case ends up being: npx downloads the entire package + dependencies, runs the tool which errors out right away, npx destroys the cache. And then I have to wait for the download yet again after fixing the flag.
Also, sometimes you just want to run the tool with a dry run before actually running it. Which requires 2 installs minimum.