question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

non-zero exit codes for npm run-script build?

See original GitHub issue

When I try to npm run-script build, if the process fails, I would expect it to return a non-zero exit code. Example:

john at Johns-MacBook-Pro-4 in ~/mysrc/weisjohn/scratch/test/hello-world                                         
$ npm run-script build

> hello-world@0.0.1 build /Users/john/mysrc/weisjohn/scratch/test/hello-world
> react-scripts build

Failed to create a production build. Reason:
Module build failed: SyntaxError: /Users/john/mysrc/weisjohn/scratch/test/hello-world/src/App.js: Identifier directly after number (5:2)
  3 | import './App.css';
  4 | 
> 5 | 10x;
    |   ^
  6 | 
  7 | class App extends Component {
  8 |   render() {
    at Parser.pp.raise (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/parser/location.js:22:13)
    at Parser.readNumber (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/tokenizer/index.js:674:78)
    at Parser.getTokenFromCode (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/tokenizer/index.js:516:23)
    at Parser.readToken (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/tokenizer/index.js:180:21)
    at Parser.<anonymous> (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/plugins/jsx/index.js:51:20)
    at Parser.readToken (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/plugins/flow.js:170:22)
    at Parser.nextToken (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/tokenizer/index.js:169:21)
    at Parser.next (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/tokenizer/index.js:81:12)
    at Parser.eat (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/tokenizer/index.js:90:14)
    at Parser.pp.isLineTerminator (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/parser/util.js:69:15)
    at Parser.pp.semicolon (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/parser/util.js:76:13)
    at Parser.pp.parseImport (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/parser/statement.js:1011:8)
    at Parser.pp.parseStatement (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/parser/statement.js:141:56)
    at Parser.parseStatement (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/plugins/flow.js:30:22)
    at Parser.pp.parseBlockBody (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/parser/statement.js:529:21)
    at Parser.pp.parseTopLevel (/Users/john/mysrc/weisjohn/scratch/test/hello-world/node_modules/react-scripts/node_modules/babylon/lib/parser/statement.js:36:8)
john at Johns-MacBook-Pro-4 in ~/mysrc/weisjohn/scratch/test/hello-world                                         
$ echo $?
0

One of the reasons I want this is to utilize npm run-script build in a pre-commit hook as follows:

#!/bin/sh
# Exit at first failure
set -e
npm run-script build

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
vjeuxcommented, Jul 28, 2016

Thanks for the investigation and the quick fix! Correctly propagating error codes is hard!

0reactions
vjeuxcommented, Jul 28, 2016

Oh good catch!

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Error running command: Build script returned non-zero exit ...
json as a dependency. Simplest way is to run: npm install gatsby --save. Locally and then add the updated package.json to your repository....
Read more >
Build not failing when npm returns a non zero exit code
As per screenshot, I have a build step that is not reporting a failure even though my build script is failing. The output...
Read more >
Build was terminated: Build script returned non-zero exit code ...
Deploy failed NPM. I am facing the error on deployment. Error on deployment. Build script returned non-zero exit code: 2 - I added...
Read more >
scripts - npm Docs
These all can be executed by running npm run-script <stage> or npm run <stage> for ... Don't exit with a non-zero error code...
Read more >
The command npm run build exited with code 1 vue
About With Command Visual 1 Run Studio Build Npm Exited Code The 2019 . ... PM: Error running command: Build script returned non-zero...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found