Build failed running test coverage report

PLEASE help us help you by writing a good post!

  • Site name: show-admin

My site is failing at building whenever a build is triggered, it fails right after running unit tests at the time that jest shows a coverage report. Here is a failed build (Netlify App).
It does not fail if I rebuild the site from the build page but cleaning the cache, so that makes me think that is something happening with the build cache context that is not correct.

My tests are being run from a bash script before building the project:

if ! CI=true npm run test-build; then
	echo "test failed" 1>&2
	exit 1
fi

I use the same script on some other projects so there shouldn’t be the root of the issue.

Hi @mrcportillo :wave:t6:, welcome to the forums! :netliconfetti:

Does your build work locally? If not please get it working locally as this is likely an issue with your code. Once that’s sorted have a look through this resource 7? It is a compilation of all of our build and deploy resources. This will be a good starting point.

If those resources don’t get you on the right track, can you share a bit more information about what you are trying to accomplish?

Lastly, please share these additional details so we can look into your experience further:

  • your project repo
  • a full copy of your latest deploy log
  • what you have already tried to get your build working
  • any error messages you have received in your terminal window or in the developer console

Thank you for the additional information!

The build works fine local, and also on netlify when I clean the cache. Here is the failed build log:

4:47:27 PM: build-image version: d55944c047ef0aee2ac01971edde72cb2a50acfe (focal)
4:47:27 PM: build-image tag: v4.16.1
4:47:27 PM: buildbot version: abbb532f43aba2e093b26ceac3d8b53e7097bae8
4:47:27 PM: Fetching cached dependencies
4:47:27 PM: Starting to download cache of 309.5MB
4:47:30 PM: Finished downloading cache in 3.029838744s
4:47:30 PM: Starting to extract cache
4:47:34 PM: Finished extracting cache in 3.714163548s
4:47:34 PM: Finished fetching cache in 6.794381315s
4:47:34 PM: Starting to prepare the repo for build
4:47:34 PM: Preparing Git Reference pull/45/head
4:47:34 PM: Parsing package.json dependencies
4:47:35 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'CI=false REACT_APP_STAGE=dev ROLLBAR_ENV=preview bash ./build.sh' versus 'npm run build' in the Netlify UI
4:47:35 PM: Section completed: initializing
4:47:36 PM: Starting build script
4:47:36 PM: Installing dependencies
4:47:36 PM: Python version set to 2.7
4:47:36 PM: Started restoring cached node version
4:47:36 PM: Finished restoring cached node version
4:47:37 PM: v16.19.0 is already installed.
4:47:37 PM: Now using node v16.19.0 (npm v8.19.3)
4:47:37 PM: Enabling node corepack
4:47:37 PM: Started restoring cached build plugins
4:47:37 PM: Finished restoring cached build plugins
4:47:37 PM: Attempting ruby version 2.7.2, read from environment
4:47:38 PM: Using ruby version 2.7.2
4:47:38 PM: Using PHP version 8.0
4:47:38 PM: No npm workspaces detected
4:47:38 PM: Started restoring cached node modules
4:47:38 PM: Finished restoring cached node modules
4:47:38 PM: Started restoring cached go cache
4:47:38 PM: Finished restoring cached go cache
4:47:38 PM: Installing Go version 1.17 (requested 1.17)
4:47:42 PM: unset GOOS;
4:47:42 PM: unset GOARCH;
4:47:42 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
4:47:42 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
4:47:42 PM: go version >&2;
4:47:42 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
4:47:42 PM: go version go1.17 linux/amd64
4:47:43 PM: Detected 1 framework(s)
4:47:43 PM: "next" at version "12.2.0"
4:47:43 PM: Installing missing commands
4:47:43 PM: Verify run directory
4:47:44 PM: ​
4:47:44 PM:   Netlify Build                                                 
4:47:44 PM: ────────────────────────────────────────────────────────────────
4:47:44 PM: ​
4:47:44 PM: ❯ Version
4:47:44 PM:   @netlify/build 29.1.3
4:47:44 PM: ​
4:47:44 PM: ❯ Flags
4:47:44 PM:   baseRelDir: true
4:47:44 PM:   buildId: 63a2112d3fa9ac00095a558c
4:47:44 PM:   deployId: 63a2112d3fa9ac00095a558e
4:47:44 PM: ​
4:47:44 PM: ❯ Current directory
4:47:44 PM:   /opt/build/repo
4:47:44 PM: ​
4:47:44 PM: ❯ Config file
4:47:44 PM:   /opt/build/repo/netlify.toml
4:47:44 PM: ​
4:47:44 PM: ❯ Context
4:47:44 PM:   deploy-preview
4:47:44 PM: ​
4:47:44 PM: ❯ Using Next.js Runtime - v4.29.3
4:47:44 PM: ​
4:47:44 PM: ❯ Loading plugins
4:47:44 PM:    - @netlify/plugin-lighthouse@4.0.3 from Netlify app
4:47:46 PM: ​
4:47:46 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
4:47:46 PM: ────────────────────────────────────────────────────────────────
4:47:46 PM: ​
4:47:46 PM: Next.js cache restored.
4:47:46 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
4:47:46 PM: ​
4:47:46 PM: (@netlify/plugin-nextjs onPreBuild completed in 171ms)
4:47:46 PM: ​
4:47:46 PM:   2. build.command from netlify.toml                            
4:47:46 PM: ────────────────────────────────────────────────────────────────
4:47:46 PM: ​
4:47:46 PM: $ CI=false REACT_APP_STAGE=dev ROLLBAR_ENV=preview bash ./build.sh
4:47:46 PM: > splunk-show-admin@0.1.3 test-build
4:47:46 PM: > jest
4:47:48 PM:  PASS  __tests__/hooks/useLocalPaginator.test.js
4:47:48 PM:  PASS  __tests__/hooks/useFilterList.test.js
4:47:49 PM: Error: An error occurred while trying to read the map file at /opt/build/repo/.netlify/plugins/deno-cli/deno_dir/gen/https/deno.land/data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImh0dHBzOi8vZGVuby5sYW5kL3N0ZEAwLjk5LjAvcGF0aC9faW50ZXJmYWNlLnRzIl0sInNvdXJjZXNDb250ZW50IjpbIi8vIENvcHlyaWdodCAyMDE4LTIwMjEgdGhlIERlbm8gYXV0aG9ycy4gQWxsIHJpZ2h0cyByZXNlcnZlZC4gTUlUIGxpY2Vuc2UuXG4vLyBUaGlzIG1vZHVsZSBpcyBicm93c2VyIGNvbXBhdGlibGUuXG5cbi8qKlxuICogQSBwYXJzZWQgcGF0aCBvYmplY3QgZ2VuZXJhdGVkIGJ5IHBhdGgucGFyc2UoKSBvciBjb25zdW1lZCBieSBwYXRoLmZvcm1hdCgpLlxuICovXG5leHBvcnQgaW50ZXJmYWNlIFBhcnNlZFBhdGgge1xuICAvKipcbiAgICogVGhlIHJvb3Qgb2YgdGhlIHBhdGggc3VjaCBhcyAnLycgb3IgJ2M6XFwnXG4gICAqL1xuICByb290OiBzdHJpbmc7XG4gIC8qKlxuICAgKiBUaGUgZnVsbCBkaXJlY3RvcnkgcGF0aCBzdWNoIGFzICcvaG9tZS91c2VyL2Rpcicgb3IgJ2M6XFxwYXRoXFxkaXInXG4gICAqL1xuICBkaXI6IHN0cmluZztcbiAgLyoqXG4gICAqIFRoZSBmaWxlIG5hbWUgaW5jbHVkaW5nIGV4dGVuc2lvbiAoaWYgYW55KSBzdWNoIGFzICdpbmRleC5odG1sJ1xuICAgKi9cbiAgYmFzZTogc3RyaW5nO1xuICAvKipcbiAgICogVGhlIGZpbGUgZXh0ZW5zaW9uIChpZiBhbnkpIHN1Y2ggYXMgJy5odG1sJ1xuICAgKi9cbiAgZXh0OiBzdHJpbmc7XG4gIC8qKlxuICAgKiBUaGUgZmlsZSBuYW1lIHdpdGhvdXQgZXh0ZW5zaW9uIChpZiBhbnkpIHN1Y2ggYXMgJ2luZGV4J1xuICAgKi9cbiAgbmFtZTogc3RyaW5nO1xufVxuXG5leHBvcnQgdHlwZSBGb3JtYXRJbnB1dFBhdGhPYmplY3QgPSBQYXJ0aWFsPFBhcnNlZFBhdGg+O1xuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDBFQUEwRTtBQUMxRSxxQ0FBcUM7QUFFckM7O0NBRUMsR0FDRCxBQXVCd0QifQ==
4:47:49 PM: Error: ENOENT: no such file or directory, open '/opt/build/repo/.netlify/plugins/deno-cli/deno_dir/gen/https/deno.land/data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImh0dHBzOi8vZGVuby5sYW5kL3N0ZEAwLjk5LjAvcGF0aC9faW50ZXJmYWNlLnRzIl0sInNvdXJjZXNDb250ZW50IjpbIi8vIENvcHlyaWdodCAyMDE4LTIwMjEgdGhlIERlbm8gYXV0aG9ycy4gQWxsIHJpZ2h0cyByZXNlc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/build/repo/node_modules/convert-source-map/index.js:40:11)
4:47:49 PM:     at new Converter (/opt/build/repo/node_modules/convert-source-map/index.js:47:32)
4:47:49 PM:     at Object.exports.fromMapFileComment (/opt/build/repo/node_modules/convert-source-map/index.js:110:10)
4:47:49 PM:     at Object.exports.fromMapFileSource (/opt/build/repo/node_modules/convert-source-map/index.js:122:22)
4:47:49 PM:     at V8ToIstanbul.load (/opt/build/repo/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:52:66)
4:47:49 PM:     at /opt/build/repo/node_modules/@jest/reporters/build/CoverageReporter.js:529:27
4:47:49 PM:     at Array.map (<anonymous>)
4:47:49 PM:     at CoverageReporter._getCoverageResult (/opt/build/repo/node_modules/@jest/reporters/build/CoverageReporter.js:500:32)
4:47:49 PM:     at CoverageReporter.onRunComplete (/opt/build/repo/node_modules/@jest/reporters/build/CoverageReporter.js:172:45)
4:47:49 PM:     at runMicrotasks (<anonymous>)
4:47:49 PM: test failed
4:47:49 PM: ​
4:47:49 PM:   "build.command" failed                                        
4:47:50 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
4:47:49 PM: ────────────────────────────────────────────────────────────────
4:47:49 PM: ​
4:47:49 PM:   Error message
4:47:49 PM:   Command failed with exit code 1: CI=false REACT_APP_STAGE=dev ROLLBAR_ENV=preview bash ./build.sh (https://ntl.fyi/exit-code-1)
4:47:49 PM: ​
4:47:49 PM:   Error location
4:47:49 PM:   In build.command from netlify.toml:
4:47:49 PM:   CI=false REACT_APP_STAGE=dev ROLLBAR_ENV=preview bash ./build.sh
4:47:49 PM: ​
4:47:49 PM:   Resolved config
4:47:49 PM:   build:
4:47:49 PM:     command: CI=false REACT_APP_STAGE=dev ROLLBAR_ENV=preview bash ./build.sh
4:47:49 PM:     commandOrigin: config
4:47:49 PM:     environment:
4:47:49 PM:       - HEADER_BASIC_AUTH
4:47:49 PM:       - NEXT_PUBLIC_ROLLBAR_POST_CLIENT_ITEM
4:47:49 PM:       - REVIEW_ID
4:47:49 PM:       - NEXT_PRIVATE_TARGET
4:47:49 PM:     publish: /opt/build/repo/.next
4:47:49 PM:     publishOrigin: config
4:47:49 PM:   plugins:
4:47:49 PM:     - inputs: {}
4:47:49 PM:       origin: ui
4:47:49 PM:       package: '@netlify/plugin-nextjs'
4:47:49 PM:     - inputs: {}
4:47:49 PM:       origin: ui
4:47:49 PM:       package: '@netlify/plugin-lighthouse'
4:47:49 PM: Caching artifacts
4:47:49 PM: Started saving node modules
4:47:49 PM: Finished saving node modules
4:47:49 PM: Started saving build plugins
4:47:49 PM: Finished saving build plugins
4:47:49 PM: Started saving pip cache
4:47:49 PM: Finished saving pip cache
4:47:49 PM: Started saving emacs cask dependencies
4:47:49 PM: Finished saving emacs cask dependencies
4:47:49 PM: Started saving maven dependencies
4:47:49 PM: Finished saving maven dependencies
4:47:49 PM: Started saving boot dependencies
4:47:49 PM: Finished saving boot dependencies
4:47:49 PM: Started saving rust rustup cache
4:47:49 PM: Finished saving rust rustup cache
4:47:49 PM: Started saving go dependencies
4:47:49 PM: Finished saving go dependencies
4:47:49 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:47:50 PM: Failing build: Failed to build site
4:47:50 PM: Finished processing build request in 23.070498819s

As I mentioned before the only thing that makes this work on netlify is cleaning the cache and rebuilding the site, that’s why I think the error is related to cache context. Sadly I cannot share my code repo as it is private.

@SamO Something that I’ve noticed reinforces the idea that the problem comes with the cache. Builds that don’t fail print this on logs:

5:11:46 PM: ────────────────────────────────────────────────────────────────
5:11:46 PM: ​
5:11:46 PM: No Next.js cache to restore.
5:11:46 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.

The ones failing this:

4:47:46 PM: ────────────────────────────────────────────────────────────────
4:47:46 PM: ​
4:47:46 PM: Next.js cache restored.
4:47:46 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.

Hope this helps debugging the issue.

@SamO I make it work with a previous version of the next js plugin (3.9.2).

Hi @mrcportillo :wave:t6:, thanks for coming back and letting us know what worked and sharing that additional information. Unfortunately the latests version of next.js isn’t supported at this time.

I’m not using the latest nextjs version, what I changed was the netlify nextjs plugin version (from 4.29.3 to 3.9.2).