Ignore errors when running npm scripts sequentially

﹥>﹥吖頭↗ 提交于 2019-12-08 15:44:41

问题


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?


回答1:


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!"




回答2:


You can go for

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

You can read more why that works here




回答3:


npm -v & npm -v 

// WORKS

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

 // WORKS


来源:https://stackoverflow.com/questions/47419424/ignore-errors-when-running-npm-scripts-sequentially

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!