thelonglqd
thelonglqd

Reputation: 1862

npx runs a node version which does not exist on my machine

I tried to run this command npx create-react-app my-app and got this error

error @typescript-eslint/[email protected]: The engine "node" is incompatible with this module. Expected version "^10.12.0 || >=12.0.0". Got "11.13.0"
error Found incompatible module.

The weird thing is I used node version 15.0.1 (latest) and yarn version 1.22.10 (latest) and the version that npx used Got "11.13.0" which does not exist on my machine.

Anybody face this problem ? Please help, many thanks in advance.

Upvotes: 2

Views: 2530

Answers (1)

Trott
Trott

Reputation: 70075

The situation may be different on Windows, but on UNIX-like operating systems (including macOS), you can find the path to the node being executed by npx with:

/usr/bin/env node -p process.execPath

This is because the npx file starts with #!/usr/bin/env node. So you can use /usr/bin/env node to execute the same node that npx will.

-p means "print the value" and process.execPath is the path to the executable.

Why do you want to do the above and not just use which node?

which will report aliases, which means that it will report the node executable you will see in your shell. That's not what npx will use, and that seems a likely possibility to explain why npx might use a different Node.js version than you expect.

$ alias node=echo
$ node foo
foo
$ which node
node: aliased to echo
$ /usr/bin/env node -p process.execPath
/Users/trott/.nvm/versions/node/v15.0.1/bin/node
$

Upvotes: 2

Related Questions