Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm run build with .bat prevent window from closing

I have a simple .bat file so i can easily execute npm commands without typing them everytime, but when i try it with 'npm run build' the window closes after the script finishes.
I cant see the results from npm run build :/.
I tried PAUSE or cmd /k but the cmd keeps closing...

create-build.bat:

cd myfolder
npm run build

Thanks in advance!

like image 549
Karl B. Avatar asked Dec 28 '17 17:12

Karl B.


People also ask

How do I stop a batch window from closing?

Add a pause statement to a batch file If you're creating a batch file and want the MS-DOS window to remain open, add PAUSE to the end of your batch file. This prompts the user to Press any key. Until the user presses any key, the window remains open instead of closing automatically.

How do I keep a batch file window open?

Type the "cmd /k" parameter before every command to keep the window from closing. To open a folder with the command prompt, hold down the "Shift" key, right-click on the folder and select "Open command window here."

How do I stop a command prompt from closing?

To prevent the Command Prompt from closing automatically:Press Windows key + R to open the Run window. Adding / K after the command keeps the window open. You can, then, close the window manually when you no longer need it to be open.

How do I pause a BAT file execution?

You can insert the pause command before a section of the batch file that you might not want to process. When pause suspends processing of the batch program, you can press CTRL+C and then press Y to stop the batch program.


2 Answers

prefix 'call' to your npm commnands: eg

call npm i -D eslint eslint-config-airbnb-base eslint-pl

This is a work around, and it's good to understand the limitations. A decent discussion can be found here: https://github.com/npm/npm/issues/2938

like image 182
Shaedo Avatar answered Nov 03 '22 00:11

Shaedo


npm evidently does an EXIT. here is the command line I use to do that.

CMD /C "C:\Program Files\nodejs\npm" i --loglevel error
like image 36
RGuggisberg Avatar answered Nov 03 '22 00:11

RGuggisberg