Home
Support Forums

Not able to build nor deploy gatsby site (https://lucid-sammet-f80fc7.netlify.app/)

Hi, I have a blog under the domain: cicerone.blog built with gatsby.

I had 1 month of not publishing anything new.

Today I decided to update one of my articles, and the build fails and gives me this error:

Deploy failed due to an error in @netlify/plugin-gatsby plugin.

This is the full log:

10:46:57 PM: Build ready to start
10:46:59 PM: build-image version: c6001ed68662a13e5deb24abec2b46058c58248a
10:46:59 PM: build-image tag: v3.9.0
10:46:59 PM: buildbot version: f650485c830eb31597911322420b99299a4303b8
10:46:59 PM: Fetching cached dependencies
10:46:59 PM: Failed to fetch cache, continuing with build
10:46:59 PM: Starting to prepare the repo for build
10:47:00 PM: No cached dependencies found. Cloning fresh repo
10:47:00 PM: git clone https://github.com/sk8Guerra/cicerone
10:47:04 PM: Preparing Git Reference refs/heads/master
10:47:05 PM: Parsing package.json dependencies
10:47:05 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'public' versus 'public/' in the Netlify UI
10:47:05 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'npm run build' versus 'gatsby build' in the Netlify UI
10:47:05 PM: Starting build script
10:47:06 PM: Installing dependencies
10:47:06 PM: Python version set to 2.7
10:47:07 PM: Downloading and installing node v14.0.0...
10:47:07 PM: Downloading https://nodejs.org/dist/v14.0.0/node-v14.0.0-linux-x64.tar.xz...
10:47:07 PM: Computing checksum with sha256sum
10:47:08 PM: Checksums matched!
10:47:11 PM: Now using node v14.0.0 (npm v6.14.4)
10:47:11 PM: Started restoring cached build plugins
10:47:11 PM: Finished restoring cached build plugins
10:47:11 PM: Attempting ruby version 2.7.2, read from environment
10:47:12 PM: Using ruby version 2.7.2
10:47:13 PM: Using PHP version 5.6
10:47:13 PM: Started restoring cached node modules
10:47:13 PM: Finished restoring cached node modules
10:47:13 PM: Installing NPM modules using NPM version 6.14.4
10:47:28 PM: npm WARN Invalid name: "Cicerone | El blog polΓ­glota"
10:47:28 PM: npm WARN repo No description
10:47:28 PM: npm WARN repo No repository field.
10:47:28 PM: npm WARN repo No README data
10:47:28 PM: npm WARN repo No license field.
10:47:28 PM: added 28 packages from 16 contributors in 14.11s
10:47:28 PM: found 0 vulnerabilities
10:47:28 PM: NPM modules installed
10:47:28 PM: Started restoring cached go cache
10:47:28 PM: Finished restoring cached go cache
10:47:28 PM: go version go1.14.4 linux/amd64
10:47:28 PM: go version go1.14.4 linux/amd64
10:47:28 PM: Installing missing commands
10:47:28 PM: Verify run directory
10:47:30 PM: ​
10:47:30 PM: ────────────────────────────────────────────────────────────────
10:47:30 PM:   Netlify Build                                                 
10:47:30 PM: ────────────────────────────────────────────────────────────────
10:47:30 PM: ​
10:47:30 PM: ❯ Version
10:47:30 PM:   @netlify/build 18.13.1
10:47:30 PM: ​
10:47:30 PM: ❯ Flags
10:47:30 PM:   baseRelDir: true
10:47:30 PM:   buildId: 61529e41dae8cf0007003b4b
10:47:30 PM:   deployId: 61529e41dae8cf0007003b4d
10:47:30 PM: ​
10:47:30 PM: ❯ Current directory
10:47:30 PM:   /opt/build/repo
10:47:30 PM: ​
10:47:30 PM: ❯ Config file
10:47:30 PM:   /opt/build/repo/netlify.toml
10:47:30 PM: ​
10:47:30 PM: ❯ Context
10:47:30 PM:   production
10:47:30 PM: ​
10:47:30 PM: ❯ Installing plugins
10:47:30 PM:    - @netlify/plugin-gatsby@1.0.3
10:47:42 PM: ​
10:47:42 PM: ❯ Loading plugins
10:47:42 PM:    - @netlify/plugin-gatsby@1.0.3 from netlify.toml
10:47:42 PM: ​
10:47:42 PM: ────────────────────────────────────────────────────────────────
10:47:42 PM:   1. onPreBuild command from @netlify/plugin-gatsby             
10:47:42 PM: ────────────────────────────────────────────────────────────────
10:47:42 PM: ​
10:47:42 PM: No Gatsby cache found. Building fresh.
10:47:42 PM: ​
10:47:42 PM: ────────────────────────────────────────────────────────────────
10:47:42 PM:   Plugin "@netlify/plugin-gatsby" failed                        
10:47:42 PM: ────────────────────────────────────────────────────────────────
10:47:42 PM: ​
10:47:42 PM:   Error message
10:47:42 PM:   Error: Could not load gatsby-config.js
10:47:42 PM:   Cannot find module 'dotenv'
10:47:42 PM:   Require stack:
10:47:42 PM:   - /opt/build/repo/gatsby-config.js
10:47:42 PM:   - /opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-gatsby/src/index.js
10:47:42 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/src/plugins/child/logic.js
10:47:42 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/src/plugins/child/load.js
10:47:42 PM:   - /opt/buildhome/.netlify-build-nvm/versions/node/v12.22.6/lib/node_modules/@netlify/build/src/plugins/child/main.js
10:47:42 PM: ​
10:47:42 PM:   Plugin details
10:47:42 PM:   Package:        @netlify/plugin-gatsby
10:47:42 PM:   Version:        1.0.3
10:47:42 PM:   Repository:     git+https://github.com/netlify/netlify-plugin-gatsby.git
10:47:42 PM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-gatsby
10:47:42 PM:   Report issues:  https://github.com/netlify/netlify-plugin-gatsby/issues
10:47:42 PM: ​
10:47:42 PM:   Error location
10:47:42 PM:   In "onPreBuild" event in "@netlify/plugin-gatsby" from netlify.toml
10:47:42 PM: ​
10:47:42 PM:   Resolved config
10:47:42 PM:   build:
10:47:42 PM:     command: npm run build
10:47:42 PM:     commandOrigin: config
10:47:42 PM:     environment:
10:47:42 PM:       - CLIENT_KEY
10:47:42 PM:       - FAUNA_URL
10:47:42 PM:       - NODE_VERSION
10:47:42 PM:       - SERVER_KEY
10:47:42 PM:       - TRACKING_ID
10:47:42 PM:     publish: /opt/build/repo/public
10:47:42 PM:     publishOrigin: config
10:47:42 PM:   plugins:
10:47:42 PM:     - inputs: {}
10:47:42 PM:       origin: config
10:47:42 PM:       package: '@netlify/plugin-gatsby'
10:47:43 PM: Caching artifacts
10:47:43 PM: Started saving node modules
10:47:43 PM: Finished saving node modules
10:47:43 PM: Started saving build plugins
10:47:43 PM: Finished saving build plugins
10:47:43 PM: Started saving pip cache
10:47:43 PM: Finished saving pip cache
10:47:43 PM: Started saving emacs cask dependencies
10:47:43 PM: Finished saving emacs cask dependencies
10:47:43 PM: Started saving maven dependencies
10:47:43 PM: Finished saving maven dependencies
10:47:43 PM: Started saving boot dependencies
10:47:43 PM: Finished saving boot dependencies
10:47:43 PM: Started saving rust rustup cache
10:47:43 PM: Finished saving rust rustup cache
10:47:43 PM: Started saving go dependencies
10:47:43 PM: Finished saving go dependencies
10:47:46 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:47:46 PM: Creating deploy upload records
10:47:46 PM: Failing build: Failed to build site
10:47:46 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
10:47:46 PM: Finished processing build request in 47.545987711s

This is how my netlify.toml looks like:

[build]
command = "npm run build"
publish = "public/"

[[plugins]]
package = "@netlify/plugin-gatsby"

[build.environment]
NODE_VERSION = '14.0.0'

I also added this plugin to my β€˜gatsy-config.js’

`gatsby-plugin-netlify`

And the gatsby version I have in my project is 2.32.11.

I first tried installing this version of the @netlify/plugin-gatsby. I also tried installing the 2 beta versions of it, but non of them worked.

What should I do to get my blog to be able to build and publish successfully?

You need to add the dotenv package to your package.json.

Thanks @hrishikesh for you answer!

I already have it in my dependencies . Should it be in the devDependencies also?

"dependencies": {
    "@apollo/client": "^3.2.5",
    "@fortawesome/fontawesome-svg-core": "^1.2.30",
    "@fortawesome/free-solid-svg-icons": "^5.14.0",
    "@fortawesome/react-fontawesome": "^0.1.11",
    "@reach/router": "^1.3.4",
    "cross-fetch": "^3.0.6",
    "dotenv": "^8.2.0",
    "gatsby": "^2.32.11",
    "gatsby-image": "^2.4.16",
    "gatsby-plugin-gtag": "^1.0.13",
    "gatsby-plugin-image": "^1.6.0",
    "gatsby-plugin-manifest": "^2.4.24",
    "gatsby-plugin-offline": "^3.2.24",
    "gatsby-plugin-react-helmet": "^3.3.10",
    "gatsby-plugin-sharp": "^2.6.28",
    "gatsby-plugin-smoothscroll": "^1.2.0",
    "gatsby-remark-attr": "^0.1.0",
    "gatsby-remark-autolink-headers": "^3.1.0",
    "gatsby-remark-grid-tables": "^0.1.0",
    "gatsby-source-filesystem": "^2.3.27",
    "gatsby-source-graphql": "^2.1.25",
    "gatsby-transformer-remark": "^2.8.31",
    "gatsby-transformer-sharp": "^2.5.13",
    "graphql-tag": "^2.11.0",
    "prop-types": "^15.7.2",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-helmet": "^6.1.0",
    "werkstatt": "^1.21.0"
  },

devDependencies prop:

 "devDependencies": {
    "@netlify/plugin-gatsby": "^2.0.0-zz-beta.0",
    "gatsby-plugin-netlify": "^4.0.0-next.0",
    "gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.22",
    "prettier": "2.1.0"
  },

The way you have it should work. Could you share your repo?

Additionally, you could try to remove dotenv entirely too. You could simply set environment variables using netlify.toml and access them using process.env.

Sure, @hrishikesh. Would you give me your GitHub username? So I can share it with you.

But if I remove the dotenv package, how would I be able to load env variables locally? only with the netlify.toml? :thinking:

With Netlify CLI you could load the variables locally too using process.env.

My GitHub username is Hrishikesh-K.

Awesome, I didn’t know that with the Netlify CLI is was able to do that. I will read more on how that works and try to do it that way.

@hrishikesh I’ve sent you an invite for the repo. :pray:t3: Let me know if you find something weird.

This is interesting, I could remove the Node 14 variable from your TOML file and added NPM_FLAGS variable with the value --legacy-peer-deps and that error goes away. There’s another error that comes up later, but maybe you could figure that out.

@hrishikesh so the netlify.toml should look like this?

[build]
command = "npm run build"
publish = "public/"

[[plugins]]
package = "@netlify/plugin-gatsby"

[build.environment]
NPM_FLAGS = '--legacy-peer-deps'

Because I tried this and throws me the exact same error. :thinking:

I set the variable in Netlify UI, I believe it should not make a difference, but maybe it does?

I also deleted your package-lock.json and moved all dependencies from devDependencies to dependencies - again I don’t think that could have changed anything, but worth a try.

Good news @hrishikesh! I’ve got it deployed again. But the solution was to upgrade to a newer version of Gatsby (3.14.1). Some of the packages didn’t work, sadly… But I made a workaround on those functionalities.

THANK YOU SO MUCH FOR YOUR HELP AND PATIENCE! :pray:t3::100:

1 Like