NPM run scripts aren't able to call `node` - node.js

Quick Summary
This is not a duplicate of the linked question, the issue there was a typo, this isn't isn't a typo.
I can run node in my bash terminal fine. If I try and run node inside an NPM script in that same bash terminal, then I get the error 'node' is not recognized as an internal or external command
Original Question
I'm having issues running npm install in one of my projects currently, but to be able to simplify all of the moving parts, I've created an NPM script in my package.json file, simply calling node nodetest.js.
The content of nodetest.js is as follows:
console.log('Node Test Success!');
On the command line, I can call node nodetest.js, and it will output the console log as expected.
If I call npm run nodetest, I get the error saying 'node' is not recognized as an internal or external command
Inside the same command line, I have access to node (/c/Program Files/nodejs/node), npm (/c/Program Files/nodejs/npm), and even npx (/c/Program Files/nodejs/npx)
Node is set in my PATH variable, and I've even added it to .bashrc.
What else could possibly be the problem?
Edit: I neglected to detail my system
Windows 10
Using Git Bash inside ConEmu
Node version 10.1.0
NPM version 6.0.0
Edit 2: Some further curiosities
If I change my NPM script to be "nodetest": "\"/c/Program Files/nodejs/node.exe\" nodetest.js", and then run npm run nodetest, I get an error in the output:
> "/c/Program Files/nodejs/node.exe" nodetest.js
The system cannot find the path specified.
BUT, if I copy that command exactly, and run it directly on the command line, it will work perfectly!

Related

NPM node-v: COMMAND NOT FOUND

node -v
npm -v
live-server
Whenever i run these commands (there maybe others I don't know of) bash returns error. I use Bash as the default terminal of VS Code for my local dev environment. The strange thing is that when i try to run npm -v or node-v outside the integrated bash terminal of VS Code and directly into an independent Bash terminal it shows the result (the version). But the same wont work in the VSC integrated terminal and returns command not found. These strange things started happening just recently. Before that it was all fine.

NodeJS script works fine on macOS but not on Windows

I am trying to run a Node project that was created by someone using a Mac, but when I run npm run start it errors out with the message:
npm ERR! missing script: clean;
The error occurs in both CMD and Powershell.
I would guess that this is a syntax issue because in our package.json there is a script with the code "npm run clean; npm run build"; I assume that on Mac it treats the semicolon as a separator between two commands, while on Windows it seems to treat the semicolon as part of the word "clean" and attempts to run the script "clean;", which doesn't exist.
Is there a way to get this script to run on my computer without changing the project? If not, is there a way to change the project so that the same script will work on both Mac and Windows?
Thanks.
To run build after clean use && to run the commands sequentially.
npm run clean && npm run build

How can i run NPM Commands in VSCode terminal?

i'm working on NPM terminal in VSCode as git and i installed an extension to support NPM but didn’t work and i just got that error
'npm' is not recognized as an internal or external command,operable program or batch file.
EDIT
i already installed node.js , i just want to work in the regular command prompt rather than node.js cmd and i got errors but it worked well when i open cmd as an admin after adding 'C:\Program Files\nodejs' to the path. now how i work with npm in cmd without opening it as an admin ? i think it’s a permissions issue tho.
You can run npm commands in a VSCode terminal the same way you would run them in any terminal:
npm <command>
This is assuming npm is properly installed.
Regarding the error you reported, maybe check this out:
'npm' is not recognized as internal or external command, operable program or batch file
What version do you have? It sounds like node is not installed.
Try to run npm -v to identify the version?

What is the 'npm' command and how can I use it?

What is npm?
Whenever I browse through some project they ask me to run npm command, something like this
npm install -g node-windows
I went through some blog posts to learn about npm and I installed Node.js. However, when I run the above code in Node.js, I get the following errors:
When I browsed further, I came to know that the windows user can run the command from the cmd prompt window, but when I do that I get some output like this:
Which just generate a text file nothing else.
My questions:
How can I get started with the AngularJS2?
How can I run an npm command?
Do I require a command prompt to run the npm command (in Windows), or I can just use Node.js?
When I use the command npm install in my command prompt, I get the following output:
How to get started with the angularJS2
Follow this link and set up the project by following instructions
How to run a npm command
npm stands for Node Package Manager, and therefore you need Node.js installed before you can run npm commands.
Follow this and install the latest version. And restart the command prompt.
Do I require a command prompt to run npm commands (in Windows), or can I just use Node.js?
Yes, you need to run npm commands from the command line (in Windows).
E.g., npm install
You get the warning because there is no package.json file present where you are running the command.
ENOENT stands for Error NO ENTrey
Navigate to the project folder using the following command and then run npm install
cd <projectpath>
The AngularJS 2 website has everything you need to be covered. Their quickstart guide alongside with the quickseed zip file helps a lot.
But, in case you missed some points:
yes, you will need npm/NodeJS. So, download the latest distribution and have a clean installation of it.
you can execute the npm command with its parameters from within the Windows cmd.
the quickseed ZIP file contains all the files you need to see a live and quick example running locally. Unzip it on your workplace and navigate to it using the windows cmd. When inside the root folder of the unzipped package, execute npm install and right after it npm start.
Take the learning path. Step by step, all your questions will be answered.
You need to use an admin prompt for global installation (-g).

Cannot get "npm install -g" to work on any packages (AppData/Roaming/npm always empty)

Running nodejs on Windows 7 Enterprise at work.
Whenever I install a node_module that needs -g access, from experience I know it's supposed to create a *.bat file in %AppData$/Roaming/npm, but for some reason it no longer does that.
For example, I will run npm install gulp -g, console looks like it installed correctly, but the files will not be in the AppData folder. And if I try running a gulp command, I get error sh.exe": gulp: command not found.
If I run the npm install gulp -g command in Console As Administrator, it installs the files into the %AppData% folder of the administrator (instead of the regular user). So if I run the gulp command through my non-administrator user, I still get error sh.exe": gulp: command not found.
Any ideas?
Found solution:
(1) Upon running the command: npm config get prefix, output is C:\Program Files (x86)\Git\local. No idea why it was set to this, as it's not the default.
But I changed it using: npm config set prefix "$APPDATA\npm".
Now when I install a --g module, ie. npm install gulp -g, it installs into this desirable directory, no longer throwing EPERM and ENOENT errors.
(2) Still need to add a PATH entry for the npm folder. The command export PATH=$PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm works temporarily, but if you close console and open it again, might not be saved (if you are not an administrator).
But you can also use echo 'export PATH=$PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm' >> ~/.bash_profile, which will create a .bash_profile file, which is run each time as your console is opened. So from this point, it should automatically add the required PATH entry.
I also faced this same issue.
After installing node.js(https://nodejs.org/en/download/) npm folder(in appdata folder) remain empty.
so, at this stage if you try to build/run angular project(ng build/ng serve), it will give error as:
The term 'ng' is not recognized as the name of a cmdlet, function, script file, or operable program.
So, for fixing this issue install angular globally in your project with following command:
npm install -g #angular/cli
Now, there would be data in npm folder(node modules etc.) and ng command will run now.

Resources