Failed during stage 'building site'; Build script returned non-zero exit code: 2

I don’t understand what’s causing this Client Error. Here is my repo: GitHub - ENguyen25/contentful-template-blog

8:59:02 PM: - info Compiled successfully
8:59:02 PM: - info Collecting page data…
8:59:03 PM: ClientError: GraphQL Error (Code: 404): {“response”:{“sys”:{“type”:“Error”,“id”:“NotFound”},“message”:“The resource could not be found.”,“details”:“The resource could not be found.”,“status”:404,“headers”:{}},“request”:{“query”:“query pageBlogPostCollection($locale: String, $preview: Boolean, $limit: Int, $order: [PageBlogPostOrder], $where: PageBlogPostFilter) {\n pageBlogPostCollection(\n limit: $limit\n locale: $locale\n preview: $preview\n order: $order\n where: $where\n ) {\n items {\n …PageBlogPostFields\n }\n }\n}\n\nfragment PageBlogPostFields on PageBlogPost {\n __typename\n sys {\n id\n spaceId\n }\n internalName\n seoFields {\n …SeoFields\n }\n slug\n author {\n …AuthorFields\n }\n publishedDate\n title\n shortDescription\n featuredImage {\n …ImageFields\n }\n content {\n json\n links {\n entries {\n block {\n …RichImageFields\n }\n }\n }\n }\n relatedBlogPostsCollection(limit: 2) {\n items {\n …ReferencePageBlogPostFields\n }\n }\n}\n\nfragment SeoFields on ComponentSeo {\n __typename\n pageTitle\n pageDescription\n canonicalUrl\n nofollow\n noindex\n shareImagesCollection(limit: 3, locale: $locale) {\n items {\n …ImageFields\n }\n }\n}\n\nfragment ImageFields on Asset {\n __typename\n sys {\n id\n }\n title\n description\n width\n height\n url\n contentType\n}\n\nfragment AuthorFields on ComponentAuthor {\n __typename\n sys {\n id\n }\n name\n avatar {\n …ImageFields\n }\n}\n\nfragment RichImageFields on ComponentRichImage {\n __typename\n internalName\n sys {\n id\n }\n image {\n …ImageFields\n }\n caption\n fullWidth\n}\n\nfragment ReferencePageBlogPostFields on PageBlogPost {\n __typename\n sys {\n id\n spaceId\n }\n slug\n author {\n …AuthorFields\n }\n publishedDate\n title\n shortDescription\n featuredImage {\n …ImageFields\n }\n}”,“variables”:{“locale”:“de-DE”,“limit”:100}}}
8:59:03 PM: at /opt/build/repo/node_modules/graphql-request/dist/index.js:395:31
8:59:03 PM: at step (/opt/build/repo/node_modules/graphql-request/dist/index.js:63:23)
8:59:03 PM: at Object.next (/opt/build/repo/node_modules/graphql-request/dist/index.js:44:53)
8:59:03 PM: at fulfilled (/opt/build/repo/node_modules/graphql-request/dist/index.js:35:58)
8:59:03 PM: at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
8:59:03 PM: response: {
8:59:03 PM: sys: { type: ‘Error’, id: ‘NotFound’ },
8:59:03 PM: message: ‘The resource could not be found.’,
8:59:03 PM: details: ‘The resource could not be found.’,
8:59:03 PM: status: 404,
8:59:03 PM: headers: Headers { [Symbol(map)]: [Object: null prototype] }
8:59:03 PM: },
8:59:03 PM: request: {
8:59:03 PM: query: ‘query pageBlogPostCollection($locale: String, $preview: Boolean, $limit: Int, $order: [PageBlogPostOrder], $where: PageBlogPostFilter) {\n’ +
8:59:03 PM: ’ pageBlogPostCollection(\n’ +
8:59:03 PM: ’ limit: $limit\n’ +
8:59:03 PM: ’ locale: $locale\n’ +
8:59:03 PM: ’ preview: $preview\n’ +
8:59:03 PM: ’ order: $order\n’ +
8:59:03 PM: ’ where: $where\n’ +
8:59:03 PM: ’ ) {\n’ +
8:59:03 PM: ’ items {\n’ +
8:59:03 PM: ’ …PageBlogPostFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ‘}\n’ +
8:59:03 PM: ‘\n’ +
8:59:03 PM: ‘fragment PageBlogPostFields on PageBlogPost {\n’ +
8:59:03 PM: ’ __typename\n’ +
8:59:03 PM: ’ sys {\n’ +
8:59:03 PM: ’ id\n’ +
8:59:03 PM: ’ spaceId\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ internalName\n’ +
8:59:03 PM: ’ seoFields {\n’ +
8:59:03 PM: ’ …SeoFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ slug\n’ +
8:59:03 PM: ’ author {\n’ +
8:59:03 PM: ’ …AuthorFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ publishedDate\n’ +
8:59:03 PM: ’ title\n’ +
8:59:03 PM: ’ shortDescription\n’ +
8:59:03 PM: ’ featuredImage {\n’ +
8:59:03 PM: ’ …ImageFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ content {\n’ +
8:59:03 PM: ’ json\n’ +
8:59:03 PM: ’ links {\n’ +
8:59:03 PM: ’ entries {\n’ +
8:59:03 PM: ’ block {\n’ +
8:59:03 PM: ’ …RichImageFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ relatedBlogPostsCollection(limit: 2) {\n’ +
8:59:03 PM: ’ items {\n’ +
8:59:03 PM: ’ …ReferencePageBlogPostFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ‘}\n’ +
8:59:03 PM: ‘\n’ +
8:59:03 PM: ‘fragment SeoFields on ComponentSeo {\n’ +
8:59:03 PM: ’ __typename\n’ +
8:59:03 PM: ’ pageTitle\n’ +
8:59:03 PM: ’ pageDescription\n’ +
8:59:03 PM: ’ canonicalUrl\n’ +
8:59:03 PM: ’ nofollow\n’ +
8:59:03 PM: ’ noindex\n’ +
8:59:03 PM: ’ shareImagesCollection(limit: 3, locale: $locale) {\n’ +
8:59:03 PM: ’ items {\n’ +
8:59:03 PM: ’ …ImageFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ‘}\n’ +
8:59:03 PM: ‘\n’ +
8:59:03 PM: ‘fragment ImageFields on Asset {\n’ +
8:59:03 PM: ’ __typename\n’ +
8:59:03 PM: ’ sys {\n’ +
8:59:03 PM: ’ id\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ title\n’ +
8:59:03 PM: ’ description\n’ +
8:59:03 PM: ’ width\n’ +
8:59:03 PM: ’ height\n’ +
8:59:03 PM: ’ url\n’ +
8:59:03 PM: ’ contentType\n’ +
8:59:03 PM: ‘}\n’ +
8:59:03 PM: ‘\n’ +
8:59:03 PM: ‘fragment AuthorFields on ComponentAuthor {\n’ +
8:59:03 PM: ’ __typename\n’ +
8:59:03 PM: ’ sys {\n’ +
8:59:03 PM: ’ id\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ name\n’ +
8:59:03 PM: ’ avatar {\n’ +
8:59:03 PM: ’ …ImageFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ‘}\n’ +
8:59:03 PM: ‘\n’ +
8:59:03 PM: ‘fragment RichImageFields on ComponentRichImage {\n’ +
8:59:03 PM: ’ __typename\n’ +
8:59:03 PM: ’ internalName\n’ +
8:59:03 PM: ’ sys {\n’ +
8:59:03 PM: ’ id\n’ +
8:59:08 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)
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ image {\n’ +
8:59:03 PM: ’ …ImageFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ caption\n’ +
8:59:03 PM: ’ fullWidth\n’ +
8:59:03 PM: ‘}\n’ +
8:59:03 PM: ‘\n’ +
8:59:03 PM: ‘fragment ReferencePageBlogPostFields on PageBlogPost {\n’ +
8:59:03 PM: ’ __typename\n’ +
8:59:03 PM: ’ sys {\n’ +
8:59:03 PM: ’ id\n’ +
8:59:03 PM: ’ spaceId\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ slug\n’ +
8:59:03 PM: ’ author {\n’ +
8:59:03 PM: ’ …AuthorFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ’ publishedDate\n’ +
8:59:03 PM: ’ title\n’ +
8:59:03 PM: ’ shortDescription\n’ +
8:59:03 PM: ’ featuredImage {\n’ +
8:59:03 PM: ’ …ImageFields\n’ +
8:59:03 PM: ’ }\n’ +
8:59:03 PM: ‘}’,
8:59:03 PM: variables: { locale: ‘de-DE’, limit: 100 }
8:59:03 PM: }
8:59:03 PM: }
8:59:03 PM: > Build error occurred
8:59:03 PM: Error: Failed to collect page data for /[slug]
8:59:03 PM: at /opt/build/repo/node_modules/next/dist/build/utils.js:1150:15
8:59:03 PM: at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
8:59:03 PM: type: ‘Error’
8:59:03 PM: }
8:59:03 PM: error Command failed with exit code 1. (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
8:59:03 PM: info Visit yarn run | Yarn for documentation about this command.
8:59:03 PM: ​
8:59:03 PM: “build.command” failed
8:59:03 PM: ────────────────────────────────────────────────────────────────
8:59:03 PM: ​
8:59:03 PM: Error message
8:59:03 PM: Command failed with exit code 1: NEXT_PUBLIC_BASE_URL=“${NEXT_PUBLIC_BASE_URL:-$URL}” yarn build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
8:59:03 PM: ​
8:59:03 PM: Error location
8:59:03 PM: In build.command from netlify.toml:
8:59:03 PM: NEXT_PUBLIC_BASE_URL=“${NEXT_PUBLIC_BASE_URL:-$URL}” yarn build
8:59:03 PM: ​
8:59:03 PM: Resolved config
8:59:03 PM: build:
8:59:03 PM: command: NEXT_PUBLIC_BASE_URL=“${NEXT_PUBLIC_BASE_URL:-$URL}” yarn build
8:59:03 PM: commandOrigin: config
8:59:03 PM: environment:
8:59:03 PM: - CONTENTFUL_ACCESS_TOKEN
8:59:03 PM: - CONTENTFUL_PREVIEW_ACCESS_TOKEN
8:59:03 PM: - CONTENTFUL_SPACE_ID
8:59:03 PM: - NEXT_PRIVATE_TARGET
8:59:03 PM: publish: /opt/build/repo/.next
8:59:03 PM: publishOrigin: ui
8:59:03 PM: plugins:
8:59:03 PM: - inputs: {}
8:59:03 PM: origin: ui
8:59:03 PM: package: ‘@netlify/plugin-nextjs’
8:59:08 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
8:59:08 PM: Failing build: Failed to build site
8:59:08 PM: Finished processing build request in 1m8.703s

@ENguyen25 The error is as shown in the log.

ClientError: GraphQL Error (Code: 404)

Your project will be making a GraphQL based request to another service to retrieve data, and that call is encountering a 404 (Not Found) error.

It relates to details and is occurring with query pageBlogPostCollection.

You should check to ensure the other service is running, that your connection details are correct and failing that, that what you’re requesting from it is correct.

Hi, in addition to what nathan said i recommend you check out our support guide here: [Support Guide] Failed build debugging advice - preparing the best help request