NPX
In a nutshell, npx
lets you use npm
packages without first installing them either globally or in a local project. I thought it was magic the first time I used it a few weeks back when I began playing with Eleventy. To use Eleventy, I just had to run Eleventy:
$ npx @11ty/eleventy
No node_modules
folder, no package.json
. Eleventy just ran, generated the static content I wanted, and left no local footprint in my project. Simple does it.
All was right with the world until today, when I discovered Eleventy released 2.0.0 and assumed that running npx @11ty/eleventy
would just pull down the latest version. It didn't:
$ npx @11ty/eleventy
...
[11ty] Wrote 10 files in 0.02 seconds (2.0ms each, v1.0.2)
As it turns out, three weeks is forever in developer time. When first running npx @11ty/eleventy
I conveniently forgot that it did indeed install Eleventy. I just didn't know where.
$ npm list -g
Nada. And as already mentioned, there was no local installation. After googling, I learned that npx
installs in its own cache, which you can find as follows:
$ npm config get cache
There will be a _npx
folder in there, which is the npx
cache. Just remove the folder to clear the cache (fair warning, this does remove all npx
cached packages).
$ cd ~/.npm/
$ rm -rf _npx
Now, when trying to run Eleventy, I see the following:
$ npx @11ty/eleventy
Need to install the following packages:
@11ty/eleventy@2.0.0
[Ok to proceed? (y)
And all is right with the world again.