What is npx and how to get it?

When trying to create a new rails app, things fail with this error:

Errno::ENOENT: No such file or directory - npx

The docs say this is needed, but don’t give information about how or where to get it. It is apparently not even supported on Unix:

$ find /usr/ports -type d -name "*npx*"
$

The code also doesn’t give much clue: that npx is called unconditionally and without actually using it.

I got to this when I tried to create with esbuild. Before that I tried to use the default importmaps, but that gives an error in the browser that it doesn’t understand mimetype application/javascript+ruby. Apparently importmaps expects the browser to compute the erb code in my JS files. :rofl:

npx is part of npm/node. you should install nodejs

Ah, thanks. Actually I have it installed, but…

$ pkg list node16 | grep npx
/usr/local/lib/node_modules/corepack/dist/npx.js
/usr/local/lib/node_modules/corepack/dist/pnpx.js
/usr/local/lib/node_modules/corepack/shims/nodewin/npx
/usr/local/lib/node_modules/corepack/shims/nodewin/npx.cmd
/usr/local/lib/node_modules/corepack/shims/nodewin/npx.ps1
/usr/local/lib/node_modules/corepack/shims/nodewin/pnpx
/usr/local/lib/node_modules/corepack/shims/nodewin/pnpx.cmd
/usr/local/lib/node_modules/corepack/shims/nodewin/pnpx.ps1
/usr/local/lib/node_modules/corepack/shims/npx
/usr/local/lib/node_modules/corepack/shims/npx.cmd
/usr/local/lib/node_modules/corepack/shims/npx.ps1
/usr/local/lib/node_modules/corepack/shims/pnpx
/usr/local/lib/node_modules/corepack/shims/pnpx.cmd
/usr/local/lib/node_modules/corepack/shims/pnpx.ps1

… never looked into these.

It’s likely npx is not bundled with node for whatever Linux distribution you’re using. You can install it like so:

npm install -g npx