Published on

Avoid Missing Script Error When Running NPM Script


There might be times when we might need to run "npm script" externally like in CI/CD without knowing whether it exists or not in the project.

For such cases, we can use --if-present flag while running the npm script.


Let's assume that our NPM project doesn't have test npm script.

In that case, here is what happens based on the flag

npm run test #  Missing script: "test"
npm run test --if-present # Silently ignores it.

Happy running scripts!