Build has been failing for over a year on live website- only local netlify CLI deploys work

I am a new developer for a client whose Gatsby website hosted on Netlify has not been building or deploying automatically for over a year. Cloning the repo locally, installing node modules, and using the Netlify CLI to netlify deploy --prod builds and works perfectly to deploy changes to the site manually but automatic deploys all fail.

The repo is private on Github but our Netlify instance is set to deploy automatically from either changes in the repo or with a deploy hook from the Sanity CMS. Both of those fail.

The last successful automatic deploy from the Sanity hook was September 21, 2021 and the last successful deploy from Github was March 7, 2022.

The website package-lock.json file is the following:

{
  "private": true,
  "name": "maue",
  "version": "1.0.0",
  "author": "@joshuarule",
  "scripts": {
    "build": "gatsby build",
    "clean-cache": "gatsby clean",
    "dev": "npm run clean-cache && gatsby develop -H 0.0.0.0 -p 8000",
    "lint": "eslint .",
    "format": "prettier-eslint --write \"**/*.js\" \"!.cache/**\" \"!node_modules/**\" \"!public/**\"",
    "test": "echo \"Write tests! -> https://gatsby.app/unit-testing\""
  },
  "devDependencies": {
    "@sanity/block-content-to-react": "^3.0.0",
    "@sanity/image-url": "^0.140.19",
    "@tailwindcss/aspect-ratio": "^0.2.0",
    "@tailwindcss/line-clamp": "^0.2.0",
    "dotenv": "^8.0.0",
    "gatsby": "^3.4.1",
    "gatsby-plugin-postcss": "^4.4.0",
    "gatsby-plugin-purgecss": "^6.0.1",
    "gatsby-plugin-react-helmet": "^4.4.0",
    "gatsby-plugin-sharp": "^3.4.1",
    "gatsby-source-filesystem": "^3.4.0",
    "gatsby-source-sanity": "^7.0.4",
    "gatsby-transformer-sharp": "^3.4.0",
    "postcss-import": "^14.0.1",
    "postcss-preset-env": "^6.7.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-helmet": "^6.1.0",
    "twin.macro": "^2.4.1"
  },
  "dependencies": {
    "@svgr/webpack": "^5.5.0",
    "axios": "^0.21.1",
    "gatsby-cli": "^3.4.1",
    "gatsby-plugin-image": "^1.7.1",
    "gatsby-plugin-manifest": "^4.3.0",
    "gatsby-plugin-modal-routing-3": "^3.0.0",
    "gatsby-plugin-netlify": "^3.14.0",
    "gatsby-plugin-sanity-image": "^0.6.0",
    "gatsby-plugin-svgr": "^3.0.0-beta.0",
    "postcss": "^8.2.14",
    "prop-types": "^15.7.2",
    "query-string": "^7.0.0",
    "react-headroom": "^3.1.1",
    "react-intersection-observer": "^8.32.0",
    "react-masonry-css": "^1.0.16",
    "react-slick": "^0.28.1",
    "slick-carousel": "^1.8.1",
    "slugify": "^1.5.3"
  }
}

The complete failed deploy log is the following:

7:03:07 PM: Build ready to start
7:03:17 PM: build-image version: 4c0c1cadee6a31c9bb8d824514030009c4c05c6a (focal)
7:03:17 PM: build-image tag: v4.15.0
7:03:17 PM: buildbot version: cc0c986a947e274d444f48f63f797a5d01f2a89a
7:03:17 PM: Fetching cached dependencies
7:03:17 PM: Failed to fetch cache, continuing with build
7:03:17 PM: Starting to prepare the repo for build
7:03:17 PM: No cached dependencies found. Cloning fresh repo
7:03:17 PM: git clone git@github.com:MAU-Estate/sanity-gatsby-blog
7:03:18 PM: Preparing Git Reference refs/heads/main
7:03:19 PM: Parsing package.json dependencies
7:03:20 PM: Different build dir detected, going to use the one specified in the Netlify configuration file: '' versus '/' in the Netlify UI
7:03:20 PM: Section completed: initializing
7:03:20 PM: Starting build script
7:03:20 PM: Installing dependencies
7:03:20 PM: Python version set to 2.7
7:03:20 PM: Attempting node version '12.18.0' from .nvmrc
7:03:21 PM: Downloading and installing node v12.18.0...
7:03:21 PM: Downloading https://nodejs.org/dist/v12.18.0/node-v12.18.0-linux-x64.tar.xz...
7:03:21 PM: Computing checksum with sha256sum
7:03:21 PM: Checksums matched!
7:03:22 PM: Now using node v12.18.0 (npm v6.14.4)
7:03:22 PM: Started restoring cached build plugins
7:03:22 PM: Finished restoring cached build plugins
7:03:22 PM: Attempting ruby version 2.7.1, read from environment
7:03:23 PM: Required ruby-2.7.1 is not installed - installing.
7:03:23 PM: Searching for binary rubies, this might take some time.
7:03:23 PM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-2.7.1.tar.bz2
7:03:23 PM: Checking requirements for ubuntu.
7:03:23 PM: Requirements installation successful.
7:03:23 PM: ruby-2.7.1 - #configure
7:03:23 PM: ruby-2.7.1 - #download
7:03:24 PM: ruby-2.7.1 - #validate archive
7:03:27 PM: ruby-2.7.1 - #extract
7:03:29 PM: ruby-2.7.1 - #validate binary
7:03:29 PM: ruby-2.7.1 - #setup
7:03:30 PM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1@global
7:03:30 PM: ruby-2.7.1 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems........................................
7:03:30 PM: ruby-2.7.1 - #generating global wrappers........
7:03:30 PM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1
7:03:30 PM: ruby-2.7.1 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
7:03:30 PM: ruby-2.7.1 - #generating default wrappers........
7:03:31 PM: Using /opt/buildhome/.rvm/gems/ruby-2.7.1
7:03:31 PM: Using ruby version 2.7.1
7:03:31 PM: Using PHP version 8.0
7:03:31 PM: No npm workspaces detected
7:03:31 PM: Started restoring cached node modules
7:03:31 PM: Finished restoring cached node modules
7:03:31 PM: Installing NPM modules using NPM version 6.14.4
7:03:32 PM: npm ERR! Cannot read property 'match' of undefined
7:03:32 PM: npm ERR! A complete log of this run can be found in:
7:03:32 PM: npm ERR!     /opt/buildhome/.npm/_logs/2022-12-08T00_03_32_111Z-debug.log
7:03:32 PM: Creating deploy upload records
7:03:32 PM: Error during NPM install
7:03:32 PM: Build was terminated: Build script returned non-zero exit code: 1
7:03:32 PM: Failing build: Failed to build site
7:03:32 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
7:03:32 PM: Finished processing build request in 15.173426231s

The things I’ve tried so far are:
(1) Verify that the build image is up to date - Ubuntu Focal 20.04 (default)
(2) Setting up a simplified version of the site using the same versions of Gatsby 3 and Node 12 to determine if either of those might be the issue. (They are not)
(3) Deleting package-lock.json files to see if the node modules were incompatible. This approach at least got me past the Initialization phase and into the build phase. New build fail log is the following:

12:12:14 PM: Netlify Build                                                 
12:12:14 PM: ────────────────────────────────────────────────────────────────
12:12:14 PM: ​
12:12:14 PM: ❯ Version
12:12:14 PM:   @netlify/build 29.11.5
12:12:14 PM: ​
12:12:14 PM: ❯ Flags
12:12:14 PM:   baseRelDir: true
12:12:14 PM:   buildId: 646b9417db543e0008b6650a
12:12:14 PM:   deployId: 646b9417db543e0008b6650c
12:12:14 PM: ​
12:12:14 PM: ❯ Current directory
12:12:14 PM:   /opt/build/repo
12:12:14 PM: ​
12:12:14 PM: ❯ Config file
12:12:14 PM:   /opt/build/repo/netlify.toml
12:12:14 PM: ​
12:12:14 PM: ❯ Context
12:12:14 PM:   branch-deploy
12:12:15 PM: ​
12:12:15 PM: ❯ Installing plugins
12:12:15 PM:    - @netlify/plugin-gatsby@3.6.2
12:12:29 PM: ​
12:12:29 PM: ❯ Loading plugins
12:12:29 PM:    - @netlify/plugin-gatsby@3.6.2 from Netlify app
12:12:33 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
12:12:31 PM: @netlify/plugin-gatsby (onPreBuild event)                     
12:12:31 PM: ────────────────────────────────────────────────────────────────
12:12:31 PM: ​
12:12:31 PM: No Gatsby cache found. Building fresh.
12:12:31 PM: Please install `gatsby-plugin-netlify` and enable it in your gatsby-config.js. https://www.gatsbyjs.com/plugins/gatsby-plugin-netlify/
12:12:31 PM: ​
12:12:31 PM: (@netlify/plugin-gatsby onPreBuild completed in 8ms)
12:12:31 PM: ​
12:12:31 PM: Build command from Netlify app                                
12:12:31 PM: ────────────────────────────────────────────────────────────────
12:12:31 PM: ​
12:12:31 PM: $ npm run build-web
12:12:31 PM: npm ERR! missing script: build-web
12:12:31 PM: npm ERR!
12:12:31 PM: npm ERR! Did you mean this?
12:12:31 PM: npm ERR!     build
12:12:31 PM: npm ERR! A complete log of this run can be found in:
12:12:31 PM: npm ERR!     /opt/buildhome/.npm/_logs/2023-05-22T16_12_31_176Z-debug.log
12:12:31 PM: ​
12:12:31 PM: "build.command" failed                                        
12:12:31 PM: ────────────────────────────────────────────────────────────────
12:12:31 PM: ​
12:12:31 PM:   Error message
12:12:31 PM:   Command failed with exit code 1: npm run build-web (https://ntl.fyi/exit-code-1)
12:12:31 PM: ​
12:12:31 PM:   Error location
12:12:31 PM:   In Build command from Netlify app:
12:12:31 PM:   npm run build-web
12:12:31 PM: ​
12:12:31 PM:   Resolved config
12:12:31 PM:   build:
12:12:31 PM:     base: /opt/build/repo
12:12:31 PM:     command: npm run build-web
12:12:31 PM:     commandOrigin: ui
12:12:31 PM:     environment:
12:12:31 PM:       - MAILCHIMP_API_KEY
12:12:31 PM:       - SANITY_DEPLOY_STUDIO_TOKEN
12:12:31 PM:     publish: /opt/build/repo/web/public
12:12:31 PM:     publishOrigin: ui
12:12:31 PM:   functionsDirectory: /opt/build/repo/web/functions
12:12:31 PM:   plugins:
12:12:31 PM:     - inputs: {}
12:12:31 PM:       origin: ui
12:12:31 PM:       package: '@netlify/plugin-gatsby'
12:12:33 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:12:33 PM: Failing build: Failed to build site
12:12:33 PM: Finished processing build request in 1m5.078s

gatsby-config.js file is the following:

// Load variables from `.env` as soon as possible
require('dotenv').config({
  path: `.env.${process.env.NODE_ENV || 'development'}`,
})

const clientConfig = require('./client-config')

const isProd = process.env.NODE_ENV === 'production'

module.exports = {
  flags: {
    FAST_DEV: true,
    DEV_SSR: false,
  },
  plugins: [
    'gatsby-plugin-postcss',
    'gatsby-plugin-react-helmet',
    {
      resolve: `gatsby-plugin-sharp`,
      options: {
        defaults: {
          formats: [`auto`, `webp`],
          placeholder: `blurred`,
          defaultQuality: 50,
          backgroundColor: `transparent`,
        },
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-image`,
    {
      resolve: `gatsby-plugin-purgecss`,
      options: {
        printRejected: false,
        tailwind: true,
      },
    },
    {
      resolve: 'gatsby-plugin-svgr',
      options: {
        prettier: true,
        svgo: true,
        replaceAttrValues: {
          '#000000': 'currentColor',
          '#000': 'currentColor',
        },
      },
    },
    `gatsby-plugin-modal-routing-3`,
    {
      resolve: 'gatsby-plugin-sanity-image',
      options: {
        ...clientConfig.sanity,
        customImageTypes: ['SanityPreviewImage', 'SanityFigure', 'SanitySlide'],
        defaultImageConfig: {
          quality: 35,
          maxWidth: 1000,
          fit: 'clip',
          auto: 'format',
        },
      },
    },
    {
      resolve: 'gatsby-source-sanity',
      options: {
        ...clientConfig.sanity,
        token: process.env.SANITY_READ_TOKEN,
        watchMode: !isProd,
        overlayDrafts: !isProd,
      },
    },
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `maryannunger.com`,
        short_name: `maryannunger`,
        description: 'Website for the estate of Mary Ann Unger.',
        start_url: `/`,
        background_color: `#1f1f1f`,
        theme_color: `#1f1f1f`,
        display: `minimal-ui`,
        icon: 'src/assets/images/favicon.png',
      },
    },
    {
      resolve: `gatsby-plugin-netlify`,
    },
  ],
}

Any help or suggestions would be so greatly appreciated. Thanks for reading!

@estate Removing the package-lock.json file appears to have resolved the first issue you were experiencing.

The second issue that you then encounter is quite simple.

12:12:31 PM: $ npm run build-web
12:12:31 PM: npm ERR! missing script: build-web

Your Netlify build command appears to be set to npm run build-web

The package.json file that you’ve provided the contents of doesn’t define a build-web script:

"scripts": {
  "build": "gatsby build",
  "clean-cache": "gatsby clean",
  "dev": "npm run clean-cache && gatsby develop -H 0.0.0.0 -p 8000",
  "lint": "eslint .",
  "format": "prettier-eslint --write \"**/*.js\" \"!.cache/**\" \"!node_modules/**\" \"!public/**\"",
  "test": "echo \"Write tests! -> https://gatsby.app/unit-testing\""
},

If that is the correct package.json, then you want to change your Build command to npm run build, so that the correct script executes.

However considering gatsby’s penchant for throwing warnings though, you’ll likely want to use CI= npm run build instead, so that you don’t immediately get failed builds due to all the warnings.

Thanks @nathanmartin. I wonder if that may be a part of the problem. In fact this repo has a root folder with its own package.json file that has the npm run build-web command run with Lerna.

The package.json I posted above is within the web folder for the site. The other folder in the root directory is for the CMS, studio.

Here is the package.json for the root directory:

{
"private": true,
"name": "maue",
"version": "1.0.0",
"scripts": {
"build": "lerna run build --parallel",
"dev": "lerna run dev --parallel",
"format": "lerna run format",
"build-studio": "lerna bootstrap && cd studio && npm run build",
"build-web": "lerna bootstrap && (cd studio && SANITY_AUTH_TOKEN=$SANITY_DEPLOY_STUDIO_TOKEN npm run graphql-deploy) && (cd web && npm run build)",
"graphql-deploy": "lerna run graphql-deploy",
"lint": "lerna run lint",
"postinstall": "lerna bootstrap",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@sanity/cli": "^2.0.0",
"lerna": "^3.13.1"
}
}

Here is a screenshot of the root directory in Github:

@estate There’s no need to wonder, the error indicates it is the problem.

You should look at the structure of your repository and then set your Basic Build Settings based on what you want to achieve.

E.g. Set the Base directory to the folder you want to build in, set the Build command that you want to execute, set the Publish directory to the folder that you want to deploy.

As you’ll see in the documentation, Netlify doesn’t look through all your directories and handle all package.json files for you, it only handles the one in the Base directory (which defaults to the root).

1 Like

Apologies for the delay- I had to troubleshoot why the Lerna issue was happening that you saw. I do not believe this is the root issue because I use the Lerna package to build both the website and CMS at the same time, and because it works fine locally. The package.json file in the root directory has build commands for each- see below:

{
  "private": true,
  "name": "maue",
  "version": "1.0.0",
  "scripts": {
    "build": "lerna run build --parallel",
    "dev": "lerna run dev --parallel",
    "format": "lerna run format",
    "build-studio": "lerna bootstrap && cd studio && npm run build",
    "build-web": "lerna bootstrap && (cd studio && SANITY_AUTH_TOKEN=$SANITY_DEPLOY_STUDIO_TOKEN npm run graphql-deploy) && (cd web && npm run build)",
    "graphql-deploy": "lerna run graphql-deploy",
    "lint": "lerna run lint",
    "postinstall": "lerna bootstrap",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "devDependencies": {
    "@sanity/cli": "^2.0.0",
    "lerna": "^3.13.1"
  }
}

Removing the package-lock.json from the root directory but leaving them in the /web and /studio directories, along with a global install with npm i --legacy-peer-deps seems to have gotten me past the Lerna error. The build now fails with what I believe is the root issue, a problem with the following error:

Plugin "@netlify/plugin-gatsby" internal error 
Error message
Could not import plugin:
Error: Cannot find module 'common-tags'
 Require stack:
/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-gatsby/lib/index.js
Plugin details
Package:        @netlify/plugin-gatsby
Version:        3.6.2

Here is a screenshot:

Here is the full log:

2:44:58 PM: Netlify Build                                                 
2:44:58 PM: ────────────────────────────────────────────────────────────────
2:44:58 PM: ​
2:44:58 PM: ❯ Version
2:44:58 PM:   @netlify/build 29.11.6
2:44:58 PM: ​
2:44:58 PM: ❯ Flags
2:44:58 PM:   apiHost: api.netlify.com
2:44:58 PM:   baseRelDir: true
2:44:58 PM:   branch: staging
2:44:58 PM:   buildId: 647643d8bdc8ff0008412872
2:44:58 PM:   buildbotServerSocket: /tmp/netlify-buildbot-socket
2:44:58 PM:   cacheDir: /opt/build/cache
2:44:58 PM:   cachedConfigPath: /tmp/netlify_config.json
2:44:58 PM:   context: branch-deploy
2:44:58 PM:   cwd: /opt/build/repo
2:44:58 PM:   deployId: 647643d8bdc8ff0008412874
2:44:58 PM:   edgeFunctionsDistDir: /tmp/edge-647643d8bdc8ff0008412874
2:44:58 PM:   featureFlags:
2:44:58 PM:     - edge_functions_cache_cli
2:44:58 PM:     - edge_functions_system_logger
2:44:58 PM:   framework: unknown
2:44:58 PM:   functionsDistDir: /tmp/zisi-647643d8bdc8ff0008412874
2:44:58 PM:   mode: buildbot
2:44:58 PM:   nodePath: /opt/buildhome/.nvm/versions/node/v14.21.3/bin/node
2:44:58 PM:   repositoryRoot: /opt/build/repo
2:44:58 PM:   saveConfig: true
2:44:58 PM:   sendStatus: true
2:44:58 PM:   siteId: 52fe0e19-432e-4d6a-b09a-21f0438e0311
2:44:58 PM:   statsd:
2:44:58 PM:     host: 10.65.141.7
2:44:58 PM:     port: 8125
2:44:58 PM:   systemLogFile: 3
2:44:58 PM:   testOpts:
2:44:58 PM:     silentLingeringProcesses: ''
2:44:58 PM: ​
2:44:58 PM: ❯ Current directory
2:44:58 PM:   /opt/build/repo
2:44:58 PM: ​
2:44:58 PM: ❯ Config file
2:44:58 PM:   No config file was defined: using default values.
2:44:58 PM: ​
2:44:58 PM: ❯ Resolved config
2:44:58 PM:   build:
2:44:58 PM:     base: /opt/build/repo
2:44:58 PM:     command: npm run build-web
2:44:58 PM:     commandOrigin: ui
2:44:58 PM:     environment:
2:44:58 PM:       - MAILCHIMP_API_KEY
2:44:58 PM:       - NETLIFY_BUILD_DEBUG
2:44:58 PM:       - SANITY_DEPLOY_STUDIO_TOKEN
2:44:58 PM:     publish: /opt/build/repo/web/public
2:44:58 PM:     publishOrigin: ui
2:44:58 PM:   functionsDirectory: /opt/build/repo/web/functions
2:44:58 PM:   plugins:
2:44:58 PM:     - inputs: {}
2:44:58 PM:       origin: ui
2:44:58 PM:       package: '@netlify/plugin-gatsby'
2:44:58 PM: ​
2:44:58 PM: ❯ Context
2:44:58 PM:   branch-deploy
2:44:58 PM: ​
2:44:58 PM: ❯ Available plugins
2:44:58 PM:    - @21yunbox/netlify-plugin-21yunbox-deploy-to-china-cdn@1.0.7
2:44:58 PM:    - @algolia/netlify-plugin-crawler@1.0.0
2:44:58 PM:    - @bharathvaj/netlify-plugin-airbrake@1.0.2
2:44:58 PM:    - @chiselstrike/netlify-plugin@0.1.0
2:44:58 PM:    - @commandbar/netlify-plugin-commandbar@0.0.4
2:44:58 PM:    - @helloample/netlify-plugin-replace@1.1.4
2:44:58 PM:    - @netlify/feature-package-pilot@0.1.11
2:44:58 PM:    - @netlify/plugin-angular-universal@1.0.1
2:44:58 PM:    - @netlify/plugin-contentful-buildtime@0.0.3
2:44:58 PM:    - @netlify/plugin-emails@1.0.3
2:44:58 PM:    - @netlify/plugin-gatsby@3.6.2
2:44:58 PM:    - @netlify/plugin-lighthouse@4.1.1
2:44:58 PM:    - @netlify/plugin-nextjs@4.37.4
2:44:58 PM:    - @netlify/plugin-sitemap@0.8.1
2:44:58 PM:    - @newrelic/netlify-plugin@1.0.2
2:44:58 PM:    - @sentry/netlify-build-plugin@1.1.1
2:44:58 PM:    - @snaplet/netlify-preview-database-plugin@2.0.0
2:44:58 PM:    - @takeshape/netlify-plugin-takeshape@1.0.0
2:44:58 PM:    - @vgs/netlify-plugin-vgs@0.0.2
2:44:58 PM:    - netlify-build-plugin-dareboost@1.2.1
2:44:58 PM:    - netlify-build-plugin-debugbear@1.0.6
2:44:58 PM:    - netlify-build-plugin-perfbeacon@1.0.3
2:44:58 PM:    - netlify-build-plugin-speedcurve@2.0.0
2:44:58 PM:    - netlify-deployment-hours-plugin@0.0.10
2:44:58 PM:    - netlify-plugin-a11y@0.0.12
2:44:58 PM:    - netlify-plugin-add-instagram@0.2.2
2:44:58 PM:    - netlify-plugin-algolia-index@0.3.0
2:44:58 PM:    - netlify-plugin-amp-server-side-rendering@1.0.2
2:44:58 PM:    - netlify-plugin-brand-guardian@1.0.1
2:44:58 PM:    - netlify-plugin-build-logger@1.0.3
2:44:58 PM:    - netlify-plugin-bundle-env@0.2.2
2:44:58 PM:    - netlify-plugin-cache-nextjs@1.4.0
2:44:58 PM:    - netlify-plugin-cecil-cache@0.3.3
2:44:58 PM:    - netlify-plugin-checklinks@4.1.1
2:44:58 PM:    - netlify-plugin-chromium@1.1.4
2:44:58 PM:    - netlify-plugin-cloudinary@1.0.3
2:44:58 PM:    - netlify-plugin-contextual-env@0.3.0
2:44:58 PM:    - netlify-plugin-cypress@2.2.0
2:44:58 PM:    - netlify-plugin-debug-cache@1.0.4
2:44:58 PM:    - netlify-plugin-encrypted-files@0.0.5
2:44:58 PM:    - netlify-plugin-fetch-feeds@0.2.3
2:44:58 PM:    - netlify-plugin-flutter@1.1.0
2:44:58 PM:    - netlify-plugin-formspree@1.0.1
2:44:58 PM:    - netlify-plugin-gatsby-cache@0.3.0
2:44:58 PM:    - netlify-plugin-get-env-vars@1.0.0
2:44:58 PM:    - netlify-plugin-ghost-inspector@1.0.1
2:44:58 PM:    - netlify-plugin-ghost-markdown@3.1.0
2:44:58 PM:    - netlify-plugin-gmail@1.1.0
2:44:58 PM:    - netlify-plugin-gridsome-cache@1.0.3
2:44:58 PM:    - netlify-plugin-hashfiles@4.0.2
2:44:58 PM:    - netlify-plugin-html-validate@1.0.0
2:44:58 PM:    - netlify-plugin-hugo-cache-resources@0.2.1
2:44:58 PM:    - netlify-plugin-image-optim@0.4.0
2:44:58 PM:    - netlify-plugin-inline-critical-css@2.0.0
2:44:58 PM:    - netlify-plugin-inline-functions-env@1.0.8
2:44:58 PM:    - netlify-plugin-inline-source@1.0.4
2:44:58 PM:    - netlify-plugin-inngest@1.0.0
2:44:58 PM:    - netlify-plugin-is-website-vulnerable@2.0.3
2:44:58 PM:    - netlify-plugin-jekyll-cache@1.0.0
2:44:58 PM:    - netlify-plugin-js-obfuscator@1.0.20
2:44:58 PM:    - netlify-plugin-minify-html@0.3.1
2:44:58 PM:    - netlify-plugin-next-dynamic@1.0.9
2:44:58 PM:    - netlify-plugin-nimbella@2.1.0
2:44:58 PM:    - netlify-plugin-no-more-404@0.0.15
2:44:58 PM:    - netlify-plugin-nx-skip-build@0.0.7
2:44:58 PM:    - netlify-plugin-pagewatch@1.0.4
2:44:58 PM:    - netlify-plugin-playwright-cache@0.0.1
2:44:58 PM:    - netlify-plugin-prerender-spa@1.0.1
2:44:58 PM:    - netlify-plugin-prisma-provider@0.3.0
2:44:58 PM:    - netlify-plugin-pushover@0.1.1
2:44:58 PM:    - netlify-plugin-qawolf@1.2.0
2:44:58 PM:    - netlify-plugin-rss@0.0.8
2:44:58 PM:    - netlify-plugin-search-index@0.1.5
2:44:58 PM:    - netlify-plugin-snyk@1.2.0
2:44:58 PM:    - netlify-plugin-stepzen@1.0.4
2:44:58 PM:    - netlify-plugin-subfont@6.0.0
2:44:58 PM:    - netlify-plugin-submit-sitemap@0.4.0
2:44:58 PM:    - netlify-plugin-to-all-events@1.3.1
2:44:58 PM:    - netlify-plugin-use-env-in-runtime@1.2.1
2:44:58 PM:    - netlify-plugin-visual-diff@2.0.0
2:44:58 PM:    - netlify-plugin-webmentions@1.1.0
2:44:58 PM:    - netlify-purge-cloudflare-on-deploy@1.2.0
2:44:58 PM: ​
2:44:58 PM: ❯ Installing plugins
2:44:58 PM:    - @netlify/plugin-gatsby@3.6.2
2:45:10 PM: ​
2:45:10 PM: ❯ Loading plugins
2:45:10 PM:    - @netlify/plugin-gatsby@3.6.2 from Netlify app (latest 3.6.2, expected 3.6.2, compatible 3.6.2)
2:45:11 PM: ​
2:45:11 PM: Plugin "@netlify/plugin-gatsby" internal error                
2:45:11 PM: ────────────────────────────────────────────────────────────────
2:45:11 PM: ​
2:45:11 PM:   Error message
2:45:11 PM:   Could not import plugin:
2:45:11 PM:   Error: Cannot find module 'common-tags'
2:45:11 PM:   Require stack:
2:45:11 PM:   - /opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-gatsby/lib/index.js
2:45:11 PM: ​
2:45:11 PM:   Plugin details
2:45:11 PM:   Package:        @netlify/plugin-gatsby
2:45:11 PM:   Version:        3.6.2
2:45:11 PM:   Repository:     git+https://github.com/netlify/netlify-plugin-gatsby.git
2:45:11 PM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-gatsby
2:45:11 PM:   Report issues:  https://github.com/netlify/netlify-plugin-gatsby/issues
2:45:11 PM: ​
2:45:11 PM:   Error location
2:45:11 PM:   While loading "@netlify/plugin-gatsby" from Netlify app
2:45:11 PM:       at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)
2:45:11 PM:       at Function.Module._load (node:internal/modules/cjs/loader:871:27)
2:45:11 PM:       at Module.require (node:internal/modules/cjs/loader:1098:19)
2:45:11 PM:       at require (node:internal/modules/cjs/helpers:108:18)
2:45:11 PM:       at Object.<anonymous> (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-gatsby/lib/index.js:10:23)
2:45:11 PM:       at Module._compile (node:internal/modules/cjs/loader:1196:14)
2:45:11 PM:       at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
2:45:11 PM:       at Module.load (node:internal/modules/cjs/loader:1074:32)
2:45:11 PM:       at Function.Module._load (node:internal/modules/cjs/loader:909:12)
2:45:11 PM:       at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
2:45:11 PM: ​
2:45:11 PM:   Error properties
2:45:11 PM:   { code: 'MODULE_NOT_FOUND' }
2:45:11 PM: ​
2:45:11 PM:   Resolved config
2:45:11 PM:   build:
2:45:11 PM:     base: /opt/build/repo
2:45:11 PM:     command: npm run build-web
2:45:11 PM:     commandOrigin: ui
2:45:11 PM:     environment:
2:45:11 PM:       - MAILCHIMP_API_KEY
2:45:11 PM:       - NETLIFY_BUILD_DEBUG
2:45:11 PM:       - SANITY_DEPLOY_STUDIO_TOKEN
2:45:11 PM:     publish: /opt/build/repo/web/public
2:45:11 PM:     publishOrigin: ui
2:45:11 PM:   functionsDirectory: /opt/build/repo/web/functions
2:45:13 PM: Failed during stage 'building site': Build script returned non-zero exit code: 3 (https://ntl.fyi/exit-code-3)
2:45:11 PM:   plugins:
2:45:11 PM:     - inputs: {}
2:45:11 PM:       origin: ui
2:45:11 PM:       package: '@netlify/plugin-gatsby'
2:45:13 PM: Build failed due to a plugin error: Build script returned non-zero exit code: 3
2:45:13 PM: Failing build: Failed to build site
2:45:13 PM: Finished processing build request in 1m35.09s

And here is a reproduction repo with the API keys removed:

@estate I can’t help with this one as I don’t work with Gatsby, nor have any interest in it.

I also intentionally don’t work with, or assist with, any of the systems that require additional complexity in the form of plugins/middleware for hosting.

Obviously that module is missing, the β€œwhy” could be any number of reasons.

If you can’t determine through your own debugging, which may be difficult with the middleware involved, you’ll need to wait for the answer to your bug report here:

Which as can be the case with projects like this, could be weeks, months or years until someone says something, or closes your issue with no response.

Perhaps this one will give you some insight as the failure point was the same:

1 Like