NodeJS script works fine on macOS but not on Windows - node.js

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

Related

VS Code: NPM Works Great at the Command Line, but "NPM Scripts" Pane Gets "/bin/sh: 1: npm: not found"

I have Node/NPM installed on my (Linux) system. When I use an ordinary terminal, or the terminal inside VS Code, I can run npm commands just fine.
However, when I try to use the "NPM Scripts" feature of VS Code (which lets you run your package.json scripts from a pane in the "Explorer"), I see:
> Executing task in folder MyProject: npm run start <
/bin/sh: 1: npm: not found The terminal process terminated with exit
code: 127
Terminal will be reused by tasks, press any key to close it.
It seems like VS Code uses a different user/shell/path/something to run these scripts, and as a result it can't find the npm command ... but I have no idea what it's using or how to fix it.
For some reason "NPM Scripts" function needs the npm file to be in /usr/local/bin/npm. Try using your linux package manager to install npm (ex: sudo apt-get install npm) or install node.js again with the package from the website.
Another option would be to create a soft-link in /usr/local/bin/ pointing to the current installation.

npm run doesn't work after install git for windows

I installed git for windows. Since then I can't run any electron project. Before the git installation it worked perfectly.
Now I have this error in the terminal on Visual Studio Code. How do I fix this?
Lifecycle scripts included in sample_gym_app:
start
electron .
PS E:\projects\electron test\gymapp> npm run
Scripts available in sample_gym_app via `npm run-script`:
pack
build --dir
I suspect you may have left out one of your npm parameters.
Try npm run start
The npm run command expects to receive the name of a script to run, oftentimes start.
If this answer is correct and works for you, consider doing some further reading on npm commands. See https://www.sitepoint.com/beginners-guide-node-package-manager/ for example.

NPM run scripts aren't able to call `node`

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!

bat file - change directory and npm install in that directory, then switch again

So I have a large number of services I'm running locally for my application, and I need a nice convenient way to first install all of their dependencies without going into the individual folders in one terminal, and second keep them up to date easier. I'm using node/npm and its not working. Here is an example of how it looks
start cd ./Service1 && npm install
start cd ./Service2 && npm install
start cd ./Service3 && npm install
and it keeps going and going. When I run the bat file, it will open a cmd prompt for each one as it should, and it changes directories just fine, but it switches back to the directory all of the services are housed in and then runs npm install. At least from what I can tell, that is what's happening. How can I change to Service1 and run npm install in it's own cmd prompt, then open another cmd prompt and do the same thing and so on?
In your code the START command starts a separate process and does a change directory. That process is its own separate environment and then closes that environment.
I think what you are attempting to do is see if the folder exists and if it does then run npm install.
So a better option would be.
IF EXIST "Service1" START "" /D Service1 call npm install

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).

Resources