- Published on
Avoid Missing Script Error When Running NPM Script
- Authors
- Name
- Ashik Nesin
- @AshikNesin
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.
Example
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!