netlify / netlify-plugin-gatsby

A build plugin to integrate Gatsby seamlessly with Netlify
https://www.npmjs.com/package/@netlify/plugin-gatsby
MIT License
91 stars 18 forks source link

[Bug]: Build has been failing for over a year on live website- only local netlify CLI deploys work #601

Closed MAU-Estate closed 1 year ago

MAU-Estate commented 1 year ago

Summary

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 root folder package-lock.json file is the following:

{
  "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"
  }
}

The web folder 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!

Steps to reproduce

  1. Create a Gatsby 3 & Node 12 site within a web folder in the root project
  2. Deploy to Netlify via Github CD
  3. Local manual deploys work, Netlify automatic deploys do not

A link to a reproduction repository

https://github.com/MAU-Estate/public-testing-repo

Plugin version

@netlify/plugin-gatsby@3.6.2

More information about your build

What OS are you using?

None

Your netlify.toml file

`netlify.toml` ```toml [build] functions = "functions" [[redirects]] from = "/api/*" to = "/.netlify/functions/:splat" status = 200 ```

Configuration

`gatsby-config.js` and options ``` // 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`, }, ], } ```

Environment

Environment ``` # Paste output from `npx envinfo` here. ```

Gatsby info

gatsby info ``` # Paste output from `gatsby info` here. ```

Your _redirects file

`_redirects` ```toml /free-standing /work /wall-mounted /work /small-bronzes /work /public-art /work /works-on-paper /work /bio /#intro /obituary /#intro https://maue.netlify.app/* https://www.maryannunger.com/:splat 301! https://www.maryannungerestate.com/* https://www.maryannunger.com/:splat 301! https://maryannungerestate.com/* https://www.maryannunger.com/:splat 301! ```

Builds logs (or link to your logs)

Build logs ``` > 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 ```

Function logs

Function logs ``` # Paste logs here ```
MAU-Estate commented 1 year ago

Was able to get past this specific issue. Deleting package-lock.json in the root but leaving those files within the subdirectories being built seems to get us past this. Will open a new issue for new problems if they occur.