March 5, 2018

Throwing Errors in Npm Build Script

From time to time you may want to throw an error from within an npm build script. This should be done in such a way that the complete execution of the script is recognized as faulty. So that for example, a build server recognizes that a script did not run successfully. You only need to output the correct exit code in order to achieve this behaviour. Ideally, the user should also receive an error message that is as accurate as possible.

Lets take a look at the code:

 

 

 

All we do is to echo some text and then we append ‘exit 1’ which indicates unsuccessful termination. Thats it.

Related Posts

Avatar photo

theCodeCampus
Developer at thecodecampus </>

Our knowledge is not simply gained through reading - it is trained, tested and constantly being expanded. Because first and foremost, we are all developers at W11K. The know-how that we acquire here as developers, consultants and information architects flows immediately into our training courses and articles for theCodeCampus.


Leave a Reply

Add code to your comment in Markdown syntax.
Like this:
`inline example`

```
code block
example
```

Your email address will not be published.