Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore errors when running npm scripts sequentially

Tags:

Whenever I build my project to be served, I have to execute three scripts:

npm run build:local     //calls tsc to compile ts into js files npm run build:webpack   //invokes webpack to bundle js files into one minified file  npm run serve           //runs my lite-server to preview files 

I wanted to run these commands sequentially as:

npm run build:local && npm run build:webpack && npm run serve 

However, due to needing to have some JQuery in my ts files, I get an error during npm run build:local that throws Cannot find name '$'. However, my code compiles it anyways, and that line is critical to my project, so it needs to be there (for now). That error stops the sequential execution of the script. Is there a way to ignore errors and keep executing down the chain?

like image 881
user3334871 Avatar asked Nov 21 '17 17:11

user3334871


1 Answers

Give this a shot:

npm run build:local ; npm run build:webpack && npm run serve 

I think of && as meaning "only run this next command if the last one doesn't error." And ; as meaning "run this next command no matter what happens to the last one." There is also ||, which means "run the next command only if the last one errors." That's handy for things like npm run build:local || echo "The build failed!"

You can also do the following if you install npm-run-all

npm-run-all -s -c build:local build:webpack serve 
  • -s run as sequence
  • -c continue on error
like image 112
Allen Luce Avatar answered Sep 20 '22 12:09

Allen Luce