Gatsby builds failing for no reason

Every build is failing for seemingly no fault of my own

I’m getting 2 main errors:

  • Error: Cannot find module ‘webpack/lib/RequestShortener’
  • Error: Cannot find module ‘acorn-dynamic-import’

Both seem like something isn’t right with the deployment pipeline.

Everything has been working fine for months building up to this, then out of nowhere it’s failing.

It did fail once due to a missing dependency of gatsby-robots-txt plugin, but I uninstalled that and now it’s throwing these errors.

Any idea on how to possible fix this?

Everything is working fine locally, and building fine locally also

Package.json

{
  "name": "gatsby-starter-default",
  "private": true,
  "description": "A simple starter to get up and developing quickly with Gatsby",
  "version": "0.1.0",
  "dependencies": {
    "axios": "^0.19.0",
    "classnames": "^2.2.6",
    "dotenv": "^8.1.0",
    "framer-motion": "^1.6.9",
    "gatsby": "^2.15.33",
    "gatsby-image": "^2.2.24",
    "gatsby-plugin-google-analytics": "^2.1.20",
    "gatsby-plugin-layout": "^1.1.10",
    "gatsby-plugin-manifest": "^2.2.20",
    "gatsby-plugin-offline": "^2.2.10",
    "gatsby-plugin-postcss": "^2.1.10",
    "gatsby-plugin-react-helmet": "^3.1.10",
    "gatsby-plugin-sharp": "^2.2.28",
    "gatsby-plugin-sitemap": "^2.2.16",
    "gatsby-source-filesystem": "^2.1.30",
    "gatsby-transformer-sharp": "^2.2.20",
    "prop-types": "^15.7.2",
    "react": "^16.10.2",
    "react-dom": "^16.10.2",
    "react-ga": "^2.7.0",
    "react-helmet": "^5.2.1",
    "react-select": "^3.0.8",
    "react-transition-group": "^4.3.0",
    "react-visibility-sensor": "^5.1.1",
    "smooth-scroll": "^16.1.0"
  },
  "devDependencies": {
    "netlify-lambda": "^1.6.3",
    "postcss-simple-vars": "^5.0.2",
    "prettier": "^1.18.2"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write src/**/*.{js,jsx}",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\"",
    "start:lambda": "netlify-lambda serve functions",
    "build:lambda": "netlify-lambda build functions",
    "prod": "npm run build && npm run build:lambda"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  },
  "browserslist": [
    ">0.25%"
  ]
}

gatsby-config.js

module.exports = {
  siteMetadata: {
    siteUrl: "https://www.syncro-group.co.uk",
    title: `Syncro – A new age of print management`,
    description: `Experts in print management, managed document services and managed IT.`,
  },
  plugins: [
    `gatsby-plugin-sitemap`,
    {
      resolve: `gatsby-plugin-google-analytics`,
      options: {
        trackingId: "UA-149201234-1",
        // Defines where to place the tracking script - `true` in the head and `false` in the body
        head: true,
      },
    },
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-plugin-postcss`,
      options: {
        postCssPlugins: [
          require("postcss-simple-vars")({
            variables: require("./src/styles/variables.js"),
          }),
        ],
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-layout`,
      options: {
        component: require.resolve(`./src/components/Layout.js`),
      },
    },
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `syncro`,
        short_name: `syncro`,
        start_url: `/`,
        background_color: `#3851F4`,
        theme_color: `#3851F4`,
        display: `minimal-ui`,
        icon: `src/images/favicon.svg`, // This path is relative to the root of the site.
      },
    },

    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.dev/offline
    // `gatsby-plugin-offline`,
  ],
}

Netlify logs

5:18:06 PM: Build ready to start
5:18:08 PM: build-image version: 9e0f207a27642d0115b1ca97cd5e8cebbe492f63
5:18:08 PM: build-image tag: v3.3.2
5:18:08 PM: buildbot version: a989558813e71e809c732e73f8044218fb8c2868
5:18:08 PM: Fetching cached dependencies
5:18:08 PM: Starting to download cache of 158.7MB
5:18:09 PM: Finished downloading cache in 844.6609ms
5:18:09 PM: Starting to extract cache
5:18:14 PM: Finished extracting cache in 5.588803213s
5:18:15 PM: Finished fetching cache in 6.519524948s
5:18:15 PM: Starting to prepare the repo for build
5:18:15 PM: Preparing Git Reference refs/heads/master
5:18:16 PM: Found netlify.toml. Overriding site configuration
5:18:16 PM: Different functions path detected, going to use the one specified in the toml file: 'lambda' versus '' in the site
5:18:16 PM: Creating functions prep folder
5:18:16 PM: Starting build script
5:18:16 PM: Installing dependencies
5:18:17 PM: Started restoring cached node version
5:18:19 PM: Finished restoring cached node version
5:18:20 PM: v10.16.3 is already installed.
5:18:21 PM: Now using node v10.16.3 (npm v6.9.0)
5:18:21 PM: Attempting ruby version 2.6.2, read from environment
5:18:23 PM: Using ruby version 2.6.2
5:18:23 PM: Using PHP version 5.6
5:18:23 PM: Started restoring cached node modules
5:18:23 PM: Finished restoring cached node modules
5:18:23 PM: Installing NPM modules using NPM version 6.9.0
5:18:50 PM: > sharp@0.23.1 install /opt/build/repo/node_modules/sharp
5:18:50 PM: > (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
5:18:50 PM: info
5:18:50 PM: sharp
5:18:50 PM:  Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-linux-x64.tar.gz
5:18:53 PM: > core-js@2.6.9 postinstall /opt/build/repo/node_modules/core-js
5:18:53 PM: > node scripts/postinstall || echo "ignore"
5:18:53 PM: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
5:18:53 PM: The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
5:18:53 PM: > https://opencollective.com/core-js 
5:18:53 PM: > https://www.patreon.com/zloirock 
5:18:53 PM: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
5:18:53 PM: > cwebp-bin@5.1.0 postinstall /opt/build/repo/node_modules/cwebp-bin
5:18:53 PM: > node lib/install.js
5:18:53 PM:   ✔ cwebp pre-build test passed successfully
5:18:53 PM: > gatsby-telemetry@1.1.29 postinstall /opt/build/repo/node_modules/gatsby-telemetry
5:18:53 PM: > node src/postinstall.js
5:18:54 PM: > gatsby-cli@2.7.56 postinstall /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli
5:18:54 PM: > node scripts/postinstall.js
5:18:54 PM: > gatsby@2.15.33 postinstall /opt/build/repo/node_modules/gatsby
5:18:54 PM: > node scripts/postinstall.js
5:18:56 PM: npm
5:18:56 PM:  WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
5:18:56 PM: npm WARN
5:18:56 PM: notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
5:18:56 PM: npm WARN
5:18:56 PM:  optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.0 (node_modules/gatsby/node_modules/fsevents):
5:18:56 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.0: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
5:18:56 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.0 (node_modules/gatsby-source-filesystem/node_modules/fsevents):
5:18:56 PM: npm
5:18:56 PM: WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.0: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
5:18:56 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.0 (node_modules/gatsby-page-utils/node_modules/fsevents):
5:18:56 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.0: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
5:18:56 PM: added 466 packages from 167 contributors, removed 76 packages, updated 254 packages and audited 34796 packages in 32.115s
5:18:56 PM: found 0 vulnerabilities
5:18:56 PM: NPM modules installed
5:18:56 PM: Started restoring cached go cache
5:18:56 PM: Finished restoring cached go cache
5:18:56 PM: unset GOOS;
5:18:56 PM: unset GOARCH;
5:18:56 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
5:18:56 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
5:18:56 PM: go version >&2;
5:18:56 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
5:18:56 PM: go version go1.12 linux/amd64
5:18:56 PM: Installing missing commands
5:18:56 PM: Verify run directory
5:18:56 PM: Executing user command: npm run prod
5:18:57 PM: > gatsby-starter-default@0.1.0 prod /opt/build/repo
5:18:57 PM: > npm run build && npm run build:lambda
5:18:57 PM: > gatsby-starter-default@0.1.0 build /opt/build/repo
5:18:57 PM: > gatsby build
5:18:59 PM: error
5:18:59 PM: gatsby build
5:18:59 PM: Build a Gatsby project.
5:18:59 PM: Options:
5:18:59 PM:   --verbose                   Turn on verbose output  [boolean] [default: false]
5:18:59 PM:   --no-color, --no-colors     Turn off the color in output  [boolean] [default: false]
5:18:59 PM:   --prefix-paths              Build site with link paths prefixed (set pathPrefix in your gatsby-config.js).  [boolean] [default: false]
5:18:59 PM:   --no-uglify                 Build site without uglifying JS bundles (for debugging).  [boolean] [default: false]
5:18:59 PM:   --open-tracing-config-file  Tracer configuration file (OpenTracing compatible). See https://gatsby.dev/tracing  [string]
5:18:59 PM:   -h, --help                  Show help  [boolean]
5:18:59 PM:   -v, --version               Show the version of the Gatsby CLI and the Gatsby package in the current project  [boolean]
5:18:59 PM: See our docs page for more info on this error: https://gatsby.dev/issue-how-to
5:18:59 PM: error Cannot find module 'acorn-dynamic-import'
5:18:59 PM: There was a problem loading the local build command. Gatsby may not be installed. Perhaps you need to run "npm install"? Cannot find module 'acorn-dynamic-import'
5:18:59 PM: See our docs page for more info on this error: https://gatsby.dev/issue-how-to
5:18:59 PM: 
5:18:59 PM:   Error: Cannot find module 'acorn-dynamic-import'
5:18:59 PM:   
5:18:59 PM:   - loader.js:636 Function.Module._resolveFilename
5:18:59 PM:     internal/modules/cjs/loader.js:636:15
5:18:59 PM:   
5:18:59 PM:   - loader.js:562 Function.Module._load
5:18:59 PM:     internal/modules/cjs/loader.js:562:25
5:18:59 PM:   
5:18:59 PM: failed during stage 'building site': Build script returned non-zero exit code: 1
5:18:59 PM:   - loader.js:692 Module.require
5:18:59 PM:     internal/modules/cjs/loader.js:692:17
5:18:59 PM:   
5:18:59 PM:   - v8-compile-cache.js:159 require
5:19:00 PM: Shutting down logging, 103 messages pending

hi there,

can you build the project locally correctly and without issues? Seems like you don’t the dependencies you need.

If no, then this definitely points towards a gatsby issue over a netlify issue - you may have more luck getting assistance from gatsby directly: https://discordapp.com/invite/br9rbUE

let us know, and we can take another look if this is truly a netlify problem :+1: