When I run the following on MacOS, I see a "local" Nx version of v16.5.1, and no "global" version:
> repo % npx nx --version
npm verbose cli /Users/me/.nvm/versions/node/v20.18.3/bin/node /Users/me/.nvm/versions/node/v20.18.3/lib/node_modules/npm/bin/npm-cli.js
npm info using npm@10.8.2
npm info using node@v20.18.3
npm verbose title npm exec nx --version
npm verbose argv "exec" "--" "nx" "--version"
npm verbose logfile logs-max:10 dir:/Users/me/.npm/_logs/2025-04-04T15_28_57_161Z-
npm verbose logfile /Users/me/.npm/_logs/2025-04-04T15_28_57_161Z-debug-0.log
Nx Version:
- Local: v16.5.1
- Global: Not found
npm verbose cwd /Users/me/code/repo
npm verbose os Darwin 23.6.0
npm verbose node v20.18.3
npm verbose npm v10.8.2
npm verbose exit 0
npm info ok
> repo % ls node_modules
ls: node_modules: No such file or directory
You can see that node_modules
is empty. I'm assuming this might be something specific to how Nx returns --version
, but I'm not sure how npx
resolves the package when nothing is installed locally or globally.
You can see npm verifies nothing is installed globally:
> repo % npm list --global nx
...
/Users/me/.nvm/versions/node/v20.18.3/lib
└── (empty)
Where would npx be pulling this nx
package/version from? I also cleared my ~/.npm/_npx
folder cache, but I assume nvm
also could be what complicates this. Is there a cache clearing command for that?
I discovered that npx
searches upward from the current directory for a local package. There was an unexpected node_modules
in the parent directory, which it was pulling the unexpected version of the nx
package from.