I have an NPM script that runs multiple tasks like this:
"multiple": "task1 && task2 && task3"
However if tasks2
fails, the script will terminate and task3
will not be run.
Is there a way to "Catch" / "Ignore" the error if it does occur, so that task3
runs either way?
Something like:
"multiple": "task1 && task2 > ignore && task3"
2
Answers
Use
;
instead of&&
:&&
is logical "and" with short-circuit. It stops the chain immediatly when the result is clear (false
) and doesn’t evaluate the remaining operations.to continue running all tasks even if one of them fails by adding the
--ignore-scripts
flag.Here’s how I would modify the package.json file:
In the example above, the
&&
operator is used to run each task sequentially. The|| true
statement is added at the end to ensure that the script continues to run even if one of the tasks fails.OR you could try the
--force
flag, which will force npm to continue running the script even if errors are thrown.