Intermittent failed deploys. Builds fine sometimes, and errors with exit code 2 other times

Netlify Site URL: rcsoldier.netlify.app

I am using the Pagefind library with AstroJs. Pagefind is part of my build script, and it must run on each build to index the pages for the search feature.

For some reason, the Netlify build process keeps erroring out about half the time. There are many times when the site builds and deploys no problem. However, sometimes I have to click “Trigger deploy” multiple times in the GUI in order to get a successful build.

Here’s the build script: npm run build && npx pagefind --source “dist”

Very simple. But the error occurs on the pagefind install sometimes and I don’t have a clue why. It also costs me quite a few build minutes which isn’t good.

This issue is arbitrary and random, which makes it very hard on me to troubleshoot. Please help me out. I’ll attach a few screenshots.

This just shows all the failed builds, followed by a success:

builds

And here’s the actual error that occurs in the output:

1 Like

Hi @justsilencia ,

Can you please give this support guide a read? Can you also confirm if this works locally first? It would also help if you attached your full build/deploy log.

Yes, it works locally and never fails… The only problem is during the installation of Pagefind, it intermittently fails. I stated this in the original post and also provided the build command I am using.

For some reason, the npx pagefind --source "dist" command fails, only on occasion about 60% of the time, when I deploy on Netlify.

I read over the link you provided, and nothing seems related to this problem.

I will provide the complete build output at the bottom of this post. I believe the only relevant part of this build is where it fails during the pagefind installation.

12:23:32 PM: build-image version: 1ca34a93198b041e44214013884c57d146a23fed (focal)
12:23:32 PM: build-image tag: v4.16.4
12:23:32 PM: buildbot version: 5d70ebdb976733297fb4c90b41002389a248e2df
12:23:32 PM: Building without cache
12:23:32 PM: Starting to prepare the repo for build
12:23:32 PM: No cached dependencies found. Cloning fresh repo
12:23:32 PM: git clone --filter=blob:none https://github.com/justsilencia/rcsoldier
12:23:33 PM: Preparing Git Reference refs/heads/main
12:23:33 PM: Parsing package.json dependencies
12:23:35 PM: Starting build script
12:23:35 PM: Installing dependencies
12:23:35 PM: Python version set to 2.7
12:23:35 PM: v16.19.0 is already installed.
12:23:36 PM: Now using node v16.19.0 (npm v8.19.3)
12:23:36 PM: Enabling Node.js Corepack
12:23:36 PM: Started restoring cached build plugins
12:23:36 PM: Finished restoring cached build plugins
12:23:36 PM: Attempting Ruby version 2.7.2, read from environment
12:23:37 PM: Using Ruby version 2.7.2
12:23:37 PM: Using PHP version 8.0
12:23:37 PM: Started restoring cached corepack dependencies
12:23:37 PM: mv: cannot move ‘/opt/build/cache/.node/corepack’ to ‘/opt/buildhome/.node/corepack’: No such file or directory
12:23:37 PM: Finished restoring cached corepack dependencies
12:23:37 PM: Started restoring cached yarn cache
12:23:37 PM: Finished restoring cached yarn cache
12:23:37 PM: No yarn workspaces detected
12:23:37 PM: Started restoring cached node modules
12:23:37 PM: Finished restoring cached node modules
12:23:37 PM: Installing npm packages using Yarn version 1.22.19
12:23:37 PM: yarn install v1.22.19
12:23:38 PM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
12:23:38 PM: [1/4] Resolving packages…
12:23:38 PM: [2/4] Fetching packages…
12:23:48 PM: [3/4] Linking dependencies…
12:23:48 PM: warning “@astrojs/mdx > @mdx-js/rollup@2.1.5” has unmet peer dependency “rollup@>=2”.
12:23:48 PM: warning " > @astrojs/react@1.2.2" has unmet peer dependency “react@^17.0.2 || ^18.0.0”.
12:23:48 PM: warning " > @astrojs/react@1.2.2" has unmet peer dependency “react-dom@^17.0.2 || ^18.0.0”.
12:23:48 PM: warning " > @astrojs/react@1.2.2" has unmet peer dependency “@types/react@^17.0.50 || ^18.0.21”.
12:23:48 PM: warning " > @astrojs/react@1.2.2" has unmet peer dependency “@types/react-dom@^17.0.17 || ^18.0.6”.
12:23:48 PM: warning " > eslint-config-prettier@8.5.0" has unmet peer dependency “eslint@>=7.0.0”.
12:23:48 PM: warning " > tailwindcss@3.2.4" has unmet peer dependency “postcss@^8.0.9”.
12:23:48 PM: warning Workspaces can only be enabled in private projects.
12:23:51 PM: [4/4] Building fresh packages…
12:23:53 PM: success Saved lockfile.
12:23:53 PM: Done in 15.26s.
12:23:53 PM: npm packages installed using Yarn
12:23:53 PM: Started restoring cached go cache
12:23:53 PM: Finished restoring cached go cache
12:23:53 PM: go version go1.19.5 linux/amd64
12:23:53 PM: Detected 1 framework(s)
12:23:53 PM: “astro” at version “1.6.10”
12:23:53 PM: Installing missing commands
12:23:53 PM: Verify run directory
12:23:53 PM: Section completed: initializing
12:23:55 PM: ​
12:23:55 PM: Netlify Build
12:23:55 PM: ────────────────────────────────────────────────────────────────
12:23:55 PM: ​
12:23:55 PM: ❯ Version
12:23:55 PM: @netlify/build 29.5.1
12:23:55 PM: ​
12:23:55 PM: ❯ Flags
12:23:55 PM: baseRelDir: true
12:23:55 PM: buildId: 63d432c2bda71041a33f159f
12:23:55 PM: deployId: 63d432c2bda71041a33f15a1
12:23:55 PM: ​
12:23:55 PM: ❯ Current directory
12:23:55 PM: /opt/build/repo
12:23:55 PM: ​
12:23:55 PM: ❯ Config file
12:23:55 PM: No config file was defined: using default values.
12:23:55 PM: ​
12:23:55 PM: ❯ Context
12:23:55 PM: production
12:23:55 PM: ​
12:23:55 PM: 1. Build command from Netlify app
12:23:55 PM: ────────────────────────────────────────────────────────────────
12:23:55 PM: ​
12:23:55 PM: $ npm run build && npx pagefind --source “dist”
12:23:55 PM: > rcsoldier@0.0.1 build
12:23:55 PM: > astro build
12:23:56 PM: 08:23:56 PM [build] output target: static
12:23:56 PM: 08:23:56 PM [build] Collecting build info…
12:23:56 PM: 08:23:56 PM [build] Completed in 372ms.
12:23:56 PM: 08:23:56 PM [build] Building static entrypoints…
12:24:00 PM: 08:24:00 PM [build] Completed in 3.44s.
12:24:00 PM:
12:24:00 PM: building client
12:24:00 PM: Completed in 291ms.
12:24:00 PM:
12:24:00 PM:
12:24:00 PM: generating static routes
12:24:00 PM: :arrow_forward: src/pages/index.astro
12:24:00 PM: └─ /index.html (+27ms)
12:24:00 PM: :arrow_forward: src/pages/AboutUs.astro
12:24:00 PM: └─ /AboutUs/index.html (+3ms)
12:24:00 PM: :arrow_forward: src/pages/Contact.astro
12:24:00 PM: └─ /Contact/index.html (+3ms)
12:24:00 PM: :arrow_forward: src/pages/blog/[page].astro
12:24:00 PM: ├─ /blog/1/index.html (+8ms)
12:24:00 PM: ├─ /blog/2/index.html (+15ms)
12:24:00 PM: └─ /blog/3/index.html (+20ms)
12:24:00 PM: :arrow_forward: src/pages/blog/[slug].astro
12:24:00 PM: ├─ /blog/fastest-drones-for-sale-under-1000/index.html (+13ms)
12:24:00 PM: ├─ /blog/fastest-rc-boat-5-best-buys/index.html (+21ms)
12:24:00 PM: ├─ /blog/rc-boating-is-a-great-hobby/index.html (+28ms)
12:24:00 PM: ├─ /blog/no-prep-rc-drag-racing/index.html (+33ms)
12:24:00 PM: ├─ /blog/rc-drift-car-racing/index.html (+38ms)
12:24:00 PM: ├─ /blog/top-10-fast-rc-cars/index.html (+46ms)
12:24:00 PM: ├─ /blog/top-5-rc-drag-cars/index.html (+55ms)
12:24:00 PM: ├─ /blog/top-5-rc-drift-cars/index.html (+61ms)
12:24:00 PM: ├─ /blog/why-you-should-race-rc-cars/index.html (+68ms)
12:24:00 PM: ├─ /blog/rc-crawling-getting-started/index.html (+74ms)
12:24:00 PM: └─ /blog/top-5-rc-semi-trucks/index.html (+84ms)
12:24:00 PM: Completed in 144ms.
12:24:00 PM:
12:24:00 PM: @astrojs/sitemap: sitemap-index.xml is created.
12:24:00 PM: astro-robots-txt: robots.txt is created.
12:24:00 PM: 08:24:00 PM [build] 17 page(s) built in 4.26s
12:24:00 PM: 08:24:00 PM [build] Complete!
12:24:02 PM: npm WARN exec The following package was not found and will be installed: pagefind@0.10.7
12:24:02 PM: ​
12:24:02 PM: “build.command” failed
12:24:02 PM: ────────────────────────────────────────────────────────────────
12:24:02 PM: ​
12:24:02 PM: Error message
12:24:02 PM: Command failed with exit code 1: npm run build && npx pagefind --source “dist” (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
12:24:02 PM: ​
12:24:02 PM: Error location
12:24:02 PM: In Build command from Netlify app:
12:24:02 PM: npm run build && npx pagefind --source “dist”
12:24:02 PM: ​
12:24:02 PM: Resolved config
12:24:02 PM: build:
12:24:02 PM: command: npm run build && npx pagefind --source “dist”
12:24:02 PM: commandOrigin: ui
12:24:02 PM: publish: /opt/build/repo/dist
12:24:02 PM: publishOrigin: ui
12:24:02 PM: Caching artifacts
12:24:02 PM: Started saving node modules
12:24:02 PM: Finished saving node modules
12:24:02 PM: Started saving build plugins
12:24:02 PM: Finished saving build plugins
12:24:02 PM: Started saving yarn cache
12:24:04 PM: Finished saving yarn cache
12:24:04 PM: Started saving pip cache
12:24:04 PM: Finished saving pip cache
12:24:04 PM: Started saving emacs cask dependencies
12:24:04 PM: Finished saving emacs cask dependencies
12:24:04 PM: Started saving maven dependencies
12:24:04 PM: Finished saving maven dependencies
12:24:04 PM: Started saving boot dependencies
12:24:04 PM: Finished saving boot dependencies
12:24:04 PM: Started saving rust rustup cache
12:24:04 PM: Finished saving rust rustup cache
12:24:04 PM: Started saving go dependencies
12:24:04 PM: Finished saving go dependencies
12:24:05 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:24:05 PM: Failing build: Failed to build site
12:24:05 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)
12:24:05 PM: Finished processing build request in 33.52s

Quite odd! We can’t see anything you can’t there - your build (well, the npx pagefind --source “dist” part anyway) unceremoniously exits with a status of 2 without logging anything.

Our team did verify that it is not, in the failing cases, spiking memory usage which you wouldn’t be able to see, so your next steps will be to increase the verbosity so you can debug why that command is failing. Looks from a quick google that you might try npx --verbose pagefind --source "dist" or perhaps even…not using npx at all but installing in the usual way via package.json and then running without using npx? Not sure why you were doing that in the first place so perhaps you have a good reason :slight_smile:

I’d wondered that myself the other day, but had noticed that it’s all that Pagefind mention in their installation docs:

Thanks for the response! I thought for sure this would be some build limitation due to the free plan, but since you have confirmed that it isn’t, I’ll have to try out the verbose flag and see if I can gain some insight as to what’s going on.

What’s super strange is that for the last two days, every single one of my builds ran flawlessly.

As for integrating the npx install into the package.json, that would be simple enough. However, I find it unlikely that it would change anything.

I’ll add the verbose flag from here on out, and I’ll report back with the results next time I get a bad build. If it ever decides to error out again lol. The thing’s performing top notch at the moment.

Hi @justsilencia thanks so much and do share your findings when you have them.

Hey guys. So I finally started getting a long string of bad builds again. Unfortunately, the --verbose flag didn’t add much insight. I will include the full build output so you can take a look and hopefully see something I don’t. I would really like to get to the bottom of this. Thanks

10:35:06 AM: build-image version: f40c5967c3e09a056e8b79397ce4f1c76d0df777 (focal)
10:35:06 AM: buildbot version: f40c5967c3e09a056e8b79397ce4f1c76d0df777
10:35:06 AM: Building without cache
10:35:06 AM: Starting to prepare the repo for build
10:35:06 AM: No cached dependencies found. Cloning fresh repo
10:35:06 AM: git clone --filter=blob:none https://github.com/justsilencia/rcsoldier
10:35:07 AM: Preparing Git Reference refs/heads/main
10:35:09 AM: Parsing package.json dependencies
10:35:10 AM: Starting build script
10:35:10 AM: Installing dependencies
10:35:10 AM: Python version set to 2.7
10:35:10 AM: v16.19.0 is already installed.
10:35:11 AM: Now using node v16.19.0 (npm v8.19.3)
10:35:11 AM: Enabling Node.js Corepack
10:35:11 AM: Started restoring cached build plugins
10:35:11 AM: Finished restoring cached build plugins
10:35:11 AM: Attempting Ruby version 2.7.2, read from environment
10:35:12 AM: Using Ruby version 2.7.2
10:35:12 AM: Using PHP version 8.0
10:35:12 AM: Started restoring cached corepack dependencies
10:35:12 AM: mv: cannot move ‘/opt/build/cache/.node/corepack’ to ‘/opt/buildhome/.node/corepack’: No such file or directory
10:35:12 AM: Finished restoring cached corepack dependencies
10:35:12 AM: Started restoring cached yarn cache
10:35:12 AM: Finished restoring cached yarn cache
10:35:12 AM: No yarn workspaces detected
10:35:12 AM: Started restoring cached node modules
10:35:12 AM: Finished restoring cached node modules
10:35:12 AM: Installing npm packages using Yarn version 1.22.19
10:35:13 AM: yarn install v1.22.19
10:35:13 AM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
10:35:13 AM: [1/4] Resolving packages…
10:35:13 AM: [2/4] Fetching packages…
10:35:22 AM: [3/4] Linking dependencies…
10:35:22 AM: warning “@astrojs/mdx > @mdx-js/rollup@2.1.5” has unmet peer dependency “rollup@>=2”.
10:35:22 AM: warning " > @astrojs/react@1.2.2" has unmet peer dependency “react@^17.0.2 || ^18.0.0”.
10:35:22 AM: warning " > @astrojs/react@1.2.2" has unmet peer dependency “react-dom@^17.0.2 || ^18.0.0”.
10:35:22 AM: warning " > @astrojs/react@1.2.2" has unmet peer dependency “@types/react@^17.0.50 || ^18.0.21”.
10:35:22 AM: warning " > @astrojs/react@1.2.2" has unmet peer dependency “@types/react-dom@^17.0.17 || ^18.0.6”.
10:35:22 AM: warning " > eslint-config-prettier@8.5.0" has unmet peer dependency “eslint@>=7.0.0”.
10:35:22 AM: warning " > tailwindcss@3.2.4" has unmet peer dependency “postcss@^8.0.9”.
10:35:22 AM: warning Workspaces can only be enabled in private projects.
10:35:25 AM: [4/4] Building fresh packages…
10:35:27 AM: success Saved lockfile.
10:35:27 AM: Done in 14.46s.
10:35:27 AM: npm packages installed using Yarn
10:35:27 AM: Started restoring cached go cache
10:35:27 AM: Finished restoring cached go cache
10:35:27 AM: go version go1.19.5 linux/amd64
10:35:28 AM: Detected 1 framework(s)
10:35:28 AM: “astro” at version “1.6.10”
10:35:28 AM: Installing missing commands
10:35:28 AM: Verify run directory
10:35:28 AM: Section completed: initializing
10:35:29 AM: ​
10:35:29 AM: Netlify Build
10:35:29 AM: ────────────────────────────────────────────────────────────────
10:35:29 AM: ​
10:35:29 AM: ❯ Version
10:35:29 AM: @netlify/build 29.5.4
10:35:29 AM: ​
10:35:29 AM: ❯ Flags
10:35:29 AM: baseRelDir: true
10:35:29 AM: buildId: 63dbd8283fd4b56451955608
10:35:29 AM: deployId: 63dbd8283fd4b5645195560a
10:35:29 AM: ​
10:35:29 AM: ❯ Current directory
10:35:29 AM: /opt/build/repo
10:35:29 AM: ​
10:35:29 AM: ❯ Config file
10:35:29 AM: No config file was defined: using default values.
10:35:29 AM: ​
10:35:29 AM: ❯ Context
10:35:29 AM: production
10:35:29 AM: ​
10:35:29 AM: 1. Build command from Netlify app
10:35:29 AM: ────────────────────────────────────────────────────────────────
10:35:29 AM: ​
10:35:29 AM: $ npm run build && npx pagefind --verbose --source “dist”
10:35:29 AM: > rcsoldier@0.0.1 build
10:35:29 AM: > astro build
10:35:31 AM: 03:35:31 PM [build] output target: static
10:35:31 AM: 03:35:31 PM [build] Collecting build info…
10:35:31 AM: 03:35:31 PM [build] Completed in 431ms.
10:35:31 AM: 03:35:31 PM [build] Building static entrypoints…
10:35:35 AM: 03:35:35 PM [build] Completed in 3.75s.
10:35:35 AM:
10:35:35 AM: building client
10:35:36 AM: Completed in 0.79s.
10:35:36 AM:
10:35:36 AM:
10:35:36 AM: generating static routes
10:35:36 AM: :arrow_forward: src/pages/index.astro
10:35:36 AM: └─ /index.html (+52ms)
10:35:36 AM: :arrow_forward: src/pages/AboutUs.astro
10:35:36 AM: └─ /AboutUs/index.html (+6ms)
10:35:36 AM: :arrow_forward: src/pages/Contact.astro
10:35:36 AM: └─ /Contact/index.html (+6ms)
10:35:36 AM: :arrow_forward: src/pages/blog/[page].astro
10:35:36 AM: ├─ /blog/1/index.html (+15ms)
10:35:36 AM: ├─ /blog/2/index.html (+23ms)
10:35:36 AM: └─ /blog/3/index.html (+31ms)
10:35:36 AM: :arrow_forward: src/pages/blog/[slug].astro
10:35:36 AM: ├─ /blog/fastest-drones-for-sale-under-1000/index.html (+19ms)
10:35:36 AM: ├─ /blog/fastest-rc-boats-5-best-buys/index.html (+104ms)
10:35:36 AM: ├─ /blog/rc-boating-is-a-great-hobby/index.html (+111ms)
10:35:36 AM: ├─ /blog/no-prep-rc-drag-racing/index.html (+118ms)
10:35:36 AM: ├─ /blog/rc-drift-car-racing/index.html (+124ms)
10:35:36 AM: ├─ /blog/top-10-fast-rc-cars/index.html (+137ms)
10:35:36 AM: ├─ /blog/top-5-rc-drag-cars/index.html (+147ms)
10:35:36 AM: ├─ /blog/top-5-rc-drift-cars/index.html (+160ms)
10:35:36 AM: ├─ /blog/traxxas-tmaxx-rc-truck-defined-a-generation/index.html (+177ms)
10:35:36 AM: ├─ /blog/why-you-should-race-rc-cars/index.html (+187ms)
10:35:36 AM: ├─ /blog/rc-crawling-getting-started/index.html (+260ms)
10:35:36 AM: └─ /blog/top-5-rc-semi-trucks/index.html (+276ms)
10:35:36 AM: Completed in 376ms.
10:35:36 AM:
10:35:36 AM: @astrojs/sitemap: sitemap-index.xml is created.
10:35:36 AM: astro-robots-txt: robots.txt is created.
10:35:36 AM: 03:35:36 PM [build] 18 page(s) built in 5.37s
10:35:36 AM: 03:35:36 PM [build] Complete!
10:35:37 AM: npm WARN exec The following package was not found and will be installed: pagefind@0.10.7
10:35:38 AM: ​
10:35:38 AM: “build.command” failed
10:35:38 AM: ────────────────────────────────────────────────────────────────
10:35:38 AM: ​
10:35:38 AM: Error message
10:35:38 AM: Command failed with exit code 1: npm run build && npx pagefind --verbose --source “dist” (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
10:35:38 AM: ​
10:35:38 AM: Error location
10:35:38 AM: In Build command from Netlify app:
10:35:38 AM: npm run build && npx pagefind --verbose --source “dist”
10:35:38 AM: ​
10:35:38 AM: Resolved config
10:35:38 AM: build:
10:35:38 AM: command: npm run build && npx pagefind --verbose --source “dist”
10:35:38 AM: commandOrigin: ui
10:35:38 AM: publish: /opt/build/repo/dist
10:35:38 AM: publishOrigin: ui
10:35:38 AM: Caching artifacts
10:35:38 AM: Started saving node modules
10:35:38 AM: Finished saving node modules
10:35:38 AM: Started saving build plugins
10:35:38 AM: Finished saving build plugins
10:35:38 AM: Started saving yarn cache
10:35:40 AM: Finished saving yarn cache
10:35:40 AM: Started saving pip cache
10:35:40 AM: Finished saving pip cache
10:35:40 AM: Started saving emacs cask dependencies
10:35:40 AM: Finished saving emacs cask dependencies
10:35:40 AM: Started saving maven dependencies
10:35:40 AM: Finished saving maven dependencies
10:35:40 AM: Started saving boot dependencies
10:35:40 AM: Finished saving boot dependencies
10:35:40 AM: Started saving rust rustup cache
10:35:40 AM: Finished saving rust rustup cache
10:35:40 AM: Started saving go dependencies
10:35:40 AM: Finished saving go dependencies
10:35:41 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:35:41 AM: Failing build: Failed to build site
10:35:41 AM: 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:35:41 AM: Finished processing build request in 35.518s