Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include the path for the node binary npm was executed with

Tags:

node.js

npm

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

like image 225
Jeb50 Avatar asked Jul 11 '18 20:07

Jeb50


People also ask

Do I need to add Nodejs to path?

By default, the installer uses the Node. js distribution in C:\Program Files\nodejs. The installer should set the C:\Program Files\nodejs\bin directory in window's PATH environment variable.

Where is npm located in command prompt?

Type in npm root -g to see what the current path your npm is installed to.

Why do we need .npmrc file?

npmrc is the configuration file that npm allows to be used globally or user level or project level to optimize your npm environment.

How do I run a node module?

The usual way to run a Node. js program is to run the globally available node command (once you install Node. js) and pass the name of the file you want to execute. While running the command, make sure you are in the same directory which contains the app.


2 Answers

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

like image 190
Jeb50 Avatar answered Oct 07 '22 10:10

Jeb50


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

like image 37
godbout Avatar answered Oct 07 '22 10:10

godbout