125

Windows, VSC, Running npm start got this

npm WARN lifecycle The node binary used for scripts is C:\Program Files\nodejs\node.exe but npm is using C:\somewhere\AppData\Roaming\npm\node_modules\node\bin\node.exe itself. Use the --scripts-prepend-node-path option to include the path for the node binary npm was executed with.

I understand it means my local version is diff from the one in the PATH variable (C:\Program Files...). How do proceed to tell it to use --scripts-prepend-node-path?

I played a trick by replacing the C:\Program Files\nodejs with C:\somewhere\AppData\Roaming\npm\node_modules\node\bin in PATH variable, it does pick up that new node.exe got but there is no node binary in the current PATH. Again recommend to use the --scrip ts-prepend-node-path option to include the path for the node binary npm was executed with

asked Jul 11, 2018 at 20:14

5 Answers 5

198

Like I said, replacing the actual path in PATH system variable didn't fix the problem completely, it still complained about binary is missing. Found this solved the there is no node binary in the current PATH problem. So I restored the original PATH, then:

Simply create a file at the root folder of the app, called .npmrc, place this line into it:

scripts-prepend-node-path=true

answered Jul 11, 2018 at 22:58
Sign up to request clarification or add additional context in comments.

3 Comments

Not sure why, but this worked for me, but the npm config set scripts-prepend-node-path auto command answer below didn't. Thanks.
Just wanted to add on that this still works as of July 2021.
This option has been removed in recent npm: github.com/npm/cli/issues/2808
134

Here's another way that works: npm config set scripts-prepend-node-path auto

answered Apr 22, 2019 at 12:12

2 Comments

Since the issue seems to happen across different projects, this is the preferable answer, so you don't need to create a .npmrc file in each project, which is what the accepted answer suggests.
Accepting this as the Accepted Answer since a) it works (in all of my environments) and b) as @kas pointed out, it makes life easier.
33

Conflict between your Node Binary and your NPM


In case the error looks something like:

npm is trying to use the same node as the one it use to run itself.

Resolve this conflict by adding the node directory to your PATH:

npm config set scripts-prepend-node-path true

From the npm documentation:

npm run sets the NODE environment variable to the node executable with which npm is executed. Also, if the --scripts-prepend-node-path is passed, the directory within which node resides is added to the PATH

answered Jun 6, 2019 at 19:43

Comments

9

Having this issue in Visual Studio 2017, I instead told VS to always use the NodeJS that I had installed from nodejs.org rather than the frozen-in-time one that ships with Visual Studio. (The one that shipped with VS2015 is so ancient it doesn't really work anymore.)

In Visual Studio, go to TOOLS> OPTIONS> search for EXTERNAL WEB TOOLS> and ensure "C:\Program Files\nodejs" (or wherever nodejs.org installed it) is first in the list of paths, adding it if necessary.

answered Jan 11, 2019 at 15:53

Comments

0

For WebStorm, invalidating caches and restarting worked for me.

answered Mar 4, 2021 at 6:07

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.