Command failed with exit code 1: gridsome build

Hello! I’m having a build issue which I cannot resolve. I have looked at the Build troubleshooting docs, but none of the solutions provided have resolved my problem.

site name: comforting-seahorse-2ae8ee.netflify.app

Everything goes well until this point:

10:20:32 PM: ────────────────────────────────────────────────────────────────
10:20:32 PM: 1. build.command from netlify.toml
10:20:32 PM: ────────────────────────────────────────────────────────────────
10:20:32 PM: ​
10:20:32 PM: $ gridsome build
10:20:33 PM: Gridsome v0.7.11
10:20:33 PM: Initializing plugins…
10:20:34 PM: SyntaxError: gridsome.server.js: /opt/build/repo/data/settings.json: Unexpected token } in JSON at position 229 (12:18)
10:20:34 PM: 10 | // Use the Data Store API here: Data Store API - Gridsome
10:20:34 PM: 11 |
10:20:34 PM: > 12 | const data = require(‘./data/settings.json’);
10:20:34 PM: | ^
10:20:34 PM: 13 |
10:20:34 PM: 14 | const Menu = store.addCollection({typeName: ‘Menu’})
10:20:34 PM: 15 |
10:20:34 PM: ​
10:20:34 PM: ────────────────────────────────────────────────────────────────
10:20:34 PM: “build.command” failed
10:20:34 PM: ────────────────────────────────────────────────────────────────
10:20:34 PM: ​
10:20:34 PM: Error message
10:20:34 PM: Command failed with exit code 1: gridsome build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
10:20:34 PM: ​
10:20:34 PM: Error location
10:20:34 PM: In build.command from netlify.toml:
10:20:34 PM: gridsome build
10:20:34 PM: ​
10:20:34 PM: Resolved config
10:20:34 PM: build:
10:20:34 PM: command: gridsome build
10:20:34 PM: commandOrigin: config
10:20:34 PM: environment:
10:20:34 PM: - NODE_VERSION
10:20:34 PM: publish: /opt/build/repo/dist
10:20:34 PM: publishOrigin: config
10:20:34 PM: Caching artifacts
10:20:34 PM: Started saving node modules
10:20:34 PM: Finished saving node modules
10:20:34 PM: Started saving build plugins
10:20:34 PM: Finished saving build plugins
10:20:34 PM: Started saving yarn cache
10:20:37 PM: Finished saving yarn cache
10:20:37 PM: Started saving pip cache
10:20:37 PM: Finished saving pip cache
10:20:37 PM: Started saving emacs cask dependencies
10:20:37 PM: Finished saving emacs cask dependencies
10:20:37 PM: Started saving maven dependencies
10:20:37 PM: Finished saving maven dependencies
10:20:37 PM: Started saving boot dependencies
10:20:37 PM: Finished saving boot dependencies
10:20:37 PM: Started saving rust rustup cache
10:20:37 PM: Finished saving rust rustup cache
10:20:37 PM: Started saving go dependencies
10:20:37 PM: Finished saving go dependencies
10:20:40 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:20:40 PM: Creating deploy upload records
10:20:40 PM: Failing build: Failed to build site
10:20:40 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
10:20:40 PM: Finished processing build request in 1m2.729367484s

Thank you so much for your help!

Hey @nemesyzygy

Based on this message, there is a syntax error in the Gridsome configuration file. Have you checked the file?

I’m pretty new to all this so I’m not sure what exactly I’m looking for. I just checked the gridsome.config.js file and there are no warnings in my IDE. Can I safely post the contents of that file here to double check? Thank you for your help!

You can post here, or provide a link to the git repository

Here is the git repo link:

https://github.com/nemesyzygy/nem-lk-docs

Much appreciated!

Move the const data = require('./data/settings.json'); from inside the module.exports to outside

e.g. instead of

module.exports = function (api) {
  api.loadSource(store => {

    const data = require('./data/settings.json');
    // rest of function...
   })
}

have

const data = require('./data/settings.json');

module.exports = function (api) {
  api.loadSource(store => {

    // rest of function...
  })
}

Thank you for the suggestion! I moved that section of the code, however the build is still not working. The error has changed slightly:

11:18:24 PM: ────────────────────────────────────────────────────────────────
11:18:24 PM: 1. build.command from netlify.toml
11:18:24 PM: ────────────────────────────────────────────────────────────────
11:18:24 PM: ​
11:18:24 PM: $ gridsome build
11:18:25 PM: Gridsome v0.7.11
11:18:25 PM: Initializing plugins…
11:18:26 PM: SyntaxError: gridsome.server.js: /opt/build/repo/data/settings.json: Unexpected token } in JSON at position 229 (8:14)
11:18:26 PM: 6 | // To restart press CTRL + C in terminal and run gridsome develop
11:18:26 PM: 7 |
11:18:26 PM: > 8 | const data = require(‘./data/settings.json’);
11:18:26 PM: | ^
11:18:26 PM: 9 |
11:18:26 PM: 10 | module.exports = function (api) {
11:18:26 PM: 11 | api.loadSource(store => {
11:18:26 PM: ​
11:18:26 PM: ────────────────────────────────────────────────────────────────
11:18:26 PM: “build.command” failed
11:18:26 PM: ────────────────────────────────────────────────────────────────
11:18:26 PM: ​
11:18:26 PM: Error message
11:18:26 PM: Command failed with exit code 1: gridsome build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
11:18:26 PM: ​
11:18:26 PM: Error location
11:18:26 PM: In build.command from netlify.toml:
11:18:26 PM: gridsome build
11:18:26 PM: ​
11:18:26 PM: Resolved config
11:18:26 PM: build:
11:18:26 PM: command: gridsome build
11:18:26 PM: commandOrigin: config
11:18:26 PM: environment:
11:18:26 PM: - NODE_VERSION
11:18:26 PM: publish: /opt/build/repo/dist
11:18:26 PM: publishOrigin: config
11:18:26 PM: Caching artifacts
11:18:26 PM: Started saving node modules
11:18:26 PM: Finished saving node modules
11:18:26 PM: Started saving build plugins
11:18:26 PM: Finished saving build plugins
11:18:26 PM: Started saving yarn cache
11:18:28 PM: Finished saving yarn cache
11:18:28 PM: Started saving pip cache
11:18:28 PM: Finished saving pip cache
11:18:28 PM: Started saving emacs cask dependencies
11:18:28 PM: Finished saving emacs cask dependencies
11:18:28 PM: Started saving maven dependencies
11:18:28 PM: Finished saving maven dependencies
11:18:28 PM: Started saving boot dependencies
11:18:28 PM: Finished saving boot dependencies
11:18:28 PM: Started saving rust rustup cache
11:18:28 PM: Finished saving rust rustup cache
11:18:28 PM: Started saving go dependencies
11:18:28 PM: Finished saving go dependencies
11:18:30 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:18:30 PM: Creating deploy upload records
11:18:30 PM: Failing build: Failed to build site
11:18:30 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
11:18:30 PM: Finished processing build request in 54.2944135s

Apologies @nemesyzygy, 'twas me not reading the error message properly :man_facepalming:

The error is in data/settings.json. The issue I see is

"section": "TBD",

where the trailing comma needs removing.

1 Like

Thank you so much!! That worked splendidly