Deploy fails - Error: Cannot find module 'gatsby-telemetry'

My build failed recently and I can’t understand why. The site runs fine locally. I haven’t changed any of the build settings. I keep getting an error that says it cannot find module ‘gatsby-telemetry’. Any advice on correcting this issue would be appreciated. Below are my build log and build/deploy settings.

Netlify site name: lucid-khorana-b0312f

Build log:
9:26:35 AM: Build ready to start
9:26:37 AM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
9:26:37 AM: build-image tag: v3.4.1
9:26:37 AM: buildbot version: 648208d76731cd5bca75c1e9bc99d2032a1f1473
9:26:37 AM: Fetching cached dependencies
9:26:37 AM: Failed to fetch cache, continuing with build
9:26:37 AM: Starting to prepare the repo for build
9:26:37 AM: No cached dependencies found. Cloning fresh repo
9:26:37 AM: git clone https://github.com/rfinkley/robertfinkley
9:26:38 AM: Preparing Git Reference refs/heads/master
9:26:39 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: ‘public’ versus ‘public/’ in the Netlify UI
9:26:39 AM: Starting build script
9:26:39 AM: Installing dependencies
9:26:39 AM: Python version set to 2.7
9:26:40 AM: v12.18.0 is already installed.
9:26:41 AM: Now using node v12.18.0 (npm v6.14.4)
9:26:41 AM: Started restoring cached build plugins
9:26:41 AM: Finished restoring cached build plugins
9:26:41 AM: Attempting ruby version 2.7.1, read from environment
9:26:42 AM: Using ruby version 2.7.1
9:26:43 AM: Using PHP version 5.6
9:26:43 AM: 5.2 is already installed.
9:26:43 AM: Using Swift version 5.2
9:26:43 AM: Started restoring cached node modules
9:26:43 AM: Finished restoring cached node modules
9:26:43 AM: Installing NPM modules using NPM version 6.14.4
9:27:39 AM: > sharp@0.25.4 install /opt/build/repo/node_modules/sharp
9:27:39 AM: > (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)
9:27:40 AM: info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.9.1/libvips-8.9.1-linux-x64.tar.gz
9:27:42 AM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/babel-runtime/node_modules/core-js
9:27:42 AM: > node -e “try{require(‘./postinstall’)}catch(e){}”
9:27:42 AM: > core-js@3.6.5 postinstall /opt/build/repo/node_modules/core-js
9:27:42 AM: > node -e “try{require(‘./postinstall’)}catch(e){}”
9:27:42 AM: > core-js-pure@3.6.5 postinstall /opt/build/repo/node_modules/core-js-pure
9:27:42 AM: > node -e “try{require(‘./postinstall’)}catch(e){}”
9:27:44 AM: > gatsby-telemetry@1.3.35 postinstall /opt/build/repo/node_modules/gatsby/node_modules/gatsby-telemetry
9:27:44 AM: > node src/postinstall.js || true
9:27:44 AM: > mozjpeg@6.0.1 postinstall /opt/build/repo/node_modules/mozjpeg
9:27:44 AM: > node lib/install.js
9:27:44 AM: :heavy_check_mark: mozjpeg pre-build test passed successfully
9:27:44 AM: > pngquant-bin@5.0.2 postinstall /opt/build/repo/node_modules/pngquant-bin
9:27:44 AM: > node lib/install.js
9:27:45 AM: :heavy_check_mark: pngquant pre-build test passed successfully
9:27:45 AM: > gatsby-cli@2.12.100 postinstall /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli
9:27:45 AM: > node scripts/postinstall.js
9:27:45 AM: > gatsby@2.24.47 postinstall /opt/build/repo/node_modules/gatsby
9:27:45 AM: > node scripts/postinstall.js
9:27:49 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/watchpack/node_modules/fsevents):
9:27:49 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
9:27:49 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
9:27:49 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
9:27:49 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/jest-haste-map/node_modules/fsevents):
9:27:49 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
9:27:49 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/gatsby/node_modules/fsevents):
9:27:49 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
9:27:49 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/chokidar/node_modules/fsevents):
9:27:49 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
9:27:49 AM: added 2918 packages from 1555 contributors and audited 2932 packages in 66.022s
9:27:53 AM: 211 packages are looking for funding
9:27:53 AM: run npm fund for details
9:27:53 AM: found 0 vulnerabilities
9:27:53 AM: NPM modules installed
9:27:53 AM: Started restoring cached go cache
9:27:53 AM: Finished restoring cached go cache
9:27:53 AM: go version go1.14.4 linux/amd64
9:27:53 AM: go version go1.14.4 linux/amd64
9:27:53 AM: Installing missing commands
9:27:53 AM: Verify run directory
9:27:55 AM: ​
9:27:55 AM: ┌─────────────────────────────┐
9:27:55 AM: │ Netlify Build │
9:27:55 AM: └─────────────────────────────┘
9:27:55 AM: ​
9:27:55 AM: ❯ Version
9:27:55 AM: @netlify/build 4.0.4
9:27:55 AM: ​
9:27:55 AM: ❯ Flags
9:27:55 AM: deployId: 5f70930b3aa9ee2501663d48
9:27:55 AM: mode: buildbot
9:27:55 AM: ​
9:27:55 AM: ❯ Current directory
9:27:55 AM: /opt/build/repo
9:27:55 AM: ​
9:27:55 AM: ❯ Config file
9:27:55 AM: No config file was defined: using default values.
9:27:55 AM: ​
9:27:55 AM: ❯ Context
9:27:55 AM: production
9:27:55 AM: ​
9:27:55 AM: ┌───────────────────────────────────┐
9:27:55 AM: │ 1. Build command from Netlify app │
9:27:55 AM: └───────────────────────────────────┘
9:27:55 AM: ​
9:27:55 AM: $ gatsby build
9:27:58 AM: success open and validate gatsby-configs - 0.023s
9:27:59 AM: error Error in “/opt/build/repo/node_modules/gatsby-plugin-page-creator/gatsby-node.js”: Cannot find module ‘gatsby-telemetry’
9:27:59 AM: Require stack:
9:27:59 AM: - /opt/build/repo/node_modules/gatsby-plugin-page-creator/create-page-wrapper.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby-plugin-page-creator/gatsby-node.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bootstrap/resolve-module-exports.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bootstrap/load-plugins/validate.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bootstrap/load-plugins/load.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bootstrap/load-plugins/index.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/services/initialize.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/services/index.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bootstrap/index.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/commands/build.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli/lib/create-cli.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli/lib/index.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bin/gatsby.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/cli.js
9:27:59 AM:
9:27:59 AM:
9:27:59 AM: Error: Cannot find module ‘gatsby-telemetry’
9:27:59 AM: Require stack:
9:27:59 AM: - /opt/build/repo/node_modules/gatsby-plugin-page-creator/create-page-wrapper. js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby-plugin-page-creator/gatsby-node.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bootstrap/resolve-module-exports.js - /opt/build/repo/node_modules/gatsby/dist/bootstrap/load-plugins/validate.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bootstrap/load-plugins/load.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bootstrap/load-plugins/index.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/services/initialize.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/services/index.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bootstrap/index.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/commands/build.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli/lib/create-cli.j s
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli/lib/index.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/dist/bin/gatsby.js
9:27:59 AM: - /opt/build/repo/node_modules/gatsby/cli.js
9:27:59 AM:
9:27:59 AM: - loader.js:966 Function.Module._resolveFilename
9:27:59 AM: internal/modules/cjs/loader.js:966:15
9:27:59 AM:
9:27:59 AM: - loader.js:842 Function.Module._load
9:27:59 AM: internal/modules/cjs/loader.js:842:27
9:27:59 AM:
9:27:59 AM: - loader.js:1026 Module.require
9:27:59 AM: internal/modules/cjs/loader.js:1026:19
9:27:59 AM:
9:27:59 AM: - v8-compile-cache.js:159 require
9:27:59 AM: [repo]/[v8-compile-cache]/v8-compile-cache.js:159:20
9:27:59 AM:
9:27:59 AM: - create-page-wrapper.js:16 Object.
9:27:59 AM: [repo]/[gatsby-plugin-page-creator]/create-page-wrapper.js:16:24
9:27:59 AM:
9:27:59 AM: - v8-compile-cache.js:178 Module._compile
9:27:59 AM: [repo]/[v8-compile-cache]/v8-compile-cache.js:178:30
9:27:59 AM:
9:27:59 AM: - loader.js:1158 Object.Module._extensions…js
9:27:59 AM: internal/modules/cjs/loader.js:1158:10
9:27:59 AM:
9:27:59 AM: - loader.js:986 Module.load
9:27:59 AM: internal/modules/cjs/loader.js:986:32
9:27:59 AM:
9:27:59 AM: - loader.js:879 Function.Module._load
9:27:59 AM: internal/modules/cjs/loader.js:879:14
9:27:59 AM:
9:27:59 AM: - loader.js:1026 Module.require
9:27:59 AM: internal/modules/cjs/loader.js:1026:19
9:27:59 AM:
9:27:59 AM: - v8-compile-cache.js:159 require
9:27:59 AM: [repo]/[v8-compile-cache]/v8-compile-cache.js:159:20
9:27:59 AM:
9:27:59 AM: - gatsby-node.js:24 Object.
9:27:59 AM: [repo]/[gatsby-plugin-page-creator]/gatsby-node.js:24:26
9:27:59 AM:
9:27:59 AM: - v8-compile-cache.js:178 Module._compile
9:27:59 AM: [repo]/[v8-compile-cache]/v8-compile-cache.js:178:30
9:27:59 AM:
9:27:59 AM: - loader.js:1158 Object.Module._extensions…js
9:27:59 AM: internal/modules/cjs/loader.js:1158:10
9:27:59 AM:
9:27:59 AM: - loader.js:986 Module.load
9:27:59 AM: internal/modules/cjs/loader.js:986:32
9:27:59 AM:
9:27:59 AM: - loader.js:879 Function.Module._load
9:27:59 AM: internal/modules/cjs/loader.js:879:14
9:27:59 AM:
9:27:59 AM:
9:27:59 AM: not finished load plugins - 0.619s
9:27:59 AM: ​
9:27:59 AM: ┌─────────────────────────────┐
9:27:59 AM: │ “build.command” failed │
9:27:59 AM: └─────────────────────────────┘
9:27:59 AM: ​
9:27:59 AM: Error message
9:27:59 AM: Command failed with exit code 1: gatsby build
9:27:59 AM: ​
9:27:59 AM: Error location
9:27:59 AM: In Build command from Netlify app:
9:27:59 AM: gatsby build
9:27:59 AM: ​
9:27:59 AM: Resolved config
9:27:59 AM: build:
9:27:59 AM: command: gatsby build
9:27:59 AM: commandOrigin: ui
9:27:59 AM: environment:
9:27:59 AM: - GATSBY_TELEMETRY_DISABLED
9:27:59 AM: publish: /opt/build/repo/public
9:27:59 AM: Caching artifacts
9:27:59 AM: Started saving node modules
9:27:59 AM: Finished saving node modules
9:27:59 AM: Started saving build plugins
9:27:59 AM: Finished saving build plugins
9:27:59 AM: Started saving pip cache
9:27:59 AM: Finished saving pip cache
9:27:59 AM: Started saving emacs cask dependencies
9:27:59 AM: Finished saving emacs cask dependencies
9:27:59 AM: Started saving maven dependencies
9:27:59 AM: Finished saving maven dependencies
9:27:59 AM: Started saving boot dependencies
9:27:59 AM: Finished saving boot dependencies
9:27:59 AM: Started saving go dependencies
9:27:59 AM: Finished saving go dependencies
9:28:02 AM: Error running command: Build script returned non-zero exit code: 2
9:28:02 AM: Failing build: Failed to build site
9:28:02 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
9:28:02 AM: Finished processing build request in 1m25.096360235s

Build & Deploy Settings:

I was able to find the fix. An article on Github explained that it is an issue with my package setup. Below is a link to the article. I had to delete my node_modules and my package-lock.json, then reinstall all packages. My deploy was successful after that.

Hi, @rfinkley. Thank you for taking the time to come back and share the solution!

This makes the community site that much more useful for people searching here for similar errors. I’m sure this will help others searching here and our support team appreciates this as well.