[Bug]: Netlify Gatsby plugin causes build failures on Gatsby 3.4 site
Crowl3y opened this issue · comments
Summary
On an existing gatsby site which previously deployed with no issues, i'm now seeing the netlify-plugin-gatsby plugin being installed during build & causing the build to fail due to the line:
import dotenv from 'dotenv';
in gatsby-config.js
which causes the error
SyntaxError: Cannot use import statement outside a module
This site had previously been untouched for an extended period of time, with regular builds running successfully.
Steps to reproduce
Build a gatsby 3.4.0 site
Error during most recent builds:
Previous successful build at the same point:
A link to a reproduction repository
No response
Plugin version
3.5.1
More information about your build
- I am building using the CLI
- I am building using file-based configuration (
netlify.toml
)
What OS are you using?
None
Your netlify.toml file
`netlify.toml`
# Paste content of your `netlify.toml` file here
Configuration
`gatsby-config.js` and options
# Paste content of your `gatsby-config.js` file, and/or command line options here. Check there is no private info in there.
Environment
Environment
# Paste output from `npx envinfo` here.
Gatsby info
gatsby info
# Paste output from `gatsby info` here.
Your _redirects file
`_redirects`
# Paste content of your `_redirects` file here
Builds logs (or link to your logs)
Failed Build Log
3:57:39 PM: build-image version: 9495be345de05eb8e91837e5d92c5afd0dbd65f6 (focal)
3:57:39 PM: buildbot version: 9495be345de05eb8e91837e5d92c5afd0dbd65f6
3:57:39 PM: Fetching cached dependencies
3:57:39 PM: Starting to download cache of 215.1MB
3:57:40 PM: Finished downloading cache in 723ms
3:57:40 PM: Starting to extract cache
3:57:42 PM: Finished extracting cache in 2.121s
3:57:42 PM: Finished fetching cache in 2.906s
3:57:42 PM: Starting to prepare the repo for build
3:57:42 PM: Preparing Git Reference refs/heads/master
3:57:43 PM: Parsing package.json dependencies
3:57:44 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'gatsby/public' versus 'public' in the Netlify UI
3:57:44 PM: Starting build script
3:57:44 PM: Installing dependencies
3:57:44 PM: Python version set to 2.7
3:57:44 PM: Started restoring cached Node.js version
3:57:45 PM: Finished restoring cached Node.js version
3:57:45 PM: v12.18.0 is already installed.
3:57:45 PM: Now using node v12.18.0 (npm v6.14.4)
3:57:45 PM: Started restoring cached build plugins
3:57:45 PM: Finished restoring cached build plugins
3:57:46 PM: Attempting Ruby version 2.7.1, read from environment
3:57:46 PM: Started restoring cached Ruby version
3:57:46 PM: Finished restoring cached Ruby version
3:57:46 PM: Using Ruby version 2.7.1
3:57:46 PM: Using PHP version 8.0
3:57:46 PM: Started restoring cached corepack dependencies
3:57:46 PM: Finished restoring cached corepack dependencies
3:57:46 PM: No npm workspaces detected
3:57:46 PM: Started restoring cached node modules
3:57:46 PM: Finished restoring cached node modules
3:57:46 PM: Bypassing sha validation. Running pre & post install scripts
3:57:46 PM: Installing npm packages using npm version 6.14.4
3:57:53 PM: npm WARN @splidejs/react-splide@0.4.4 requires a peer of react@16.13.1 but none is installed. You must install peer dependencies yourself.
3:57:53 PM: npm WARN @splidejs/react-splide@0.4.4 requires a peer of react-dom@16.13.1 but none is installed. You must install peer dependencies yourself.
3:57:53 PM: npm WARN express-graphql@0.9.0 requires a peer of graphql@^14.4.1 but none is installed. You must install peer dependencies yourself.
3:57:53 PM: npm WARN slick-carousel@1.8.1 requires a peer of jquery@>=1.8.0 but none is installed. You must install peer dependencies yourself.
3:57:53 PM: npm WARN ts-node@9.1.1 requires a peer of typescript@>=2.7 but none is installed. You must install peer dependencies yourself.
3:57:53 PM: npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
3:57:53 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
3:57:53 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
3:57:53 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
3:57:53 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
3:57:53 PM: audited 2517 packages in 6.378s
3:57:54 PM: 221 packages are looking for funding
3:57:54 PM: run `npm fund` for details
3:57:54 PM: found 329 vulnerabilities (10 low, 133 moderate, 151 high, 35 critical)
3:57:54 PM: run `npm audit fix` to fix them, or `npm audit` for details
3:57:54 PM: npm packages installed
3:57:54 PM: Started restoring cached go cache
3:57:54 PM: Finished restoring cached go cache
3:57:54 PM: Installing Go version 1.14.4 (requested 1.14.4)
3:57:57 PM: go version go1.14.4 linux/amd64
3:57:58 PM: Detected 1 framework(s)
3:57:58 PM: "gatsby" at version "3.4.0"
3:57:58 PM: Installing missing commands
3:57:58 PM: Verify run directory
3:57:58 PM: Section completed: initializing
3:57:59 PM:
3:57:59 PM: Netlify Build
3:57:59 PM: ────────────────────────────────────────────────────────────────
3:57:59 PM:
3:57:59 PM: ❯ Version
3:57:59 PM: @netlify/build 29.5.4
3:57:59 PM:
3:57:59 PM: ❯ Flags
3:57:59 PM: baseRelDir: true
3:57:59 PM: buildId: 63e47d32e198733cc805d7b5
3:57:59 PM: deployId: 63e47d3d97f34300088337ee
3:57:59 PM:
3:57:59 PM: ❯ Current directory
3:57:59 PM: /opt/build/repo/gatsby
3:57:59 PM:
3:57:59 PM: ❯ Config file
3:57:59 PM: No config file was defined: using default values.
3:57:59 PM:
3:57:59 PM: ❯ Context
3:57:59 PM: production
3:57:59 PM:
3:57:59 PM: ❯ Installing plugins
3:57:59 PM: - @netlify/plugin-gatsby@3.5.1
3:58:13 PM:
3:58:13 PM: ❯ Loading plugins
3:58:13 PM: - @netlify/plugin-gatsby@3.5.1 from undefined
3:58:14 PM:
3:58:14 PM: 1. @netlify/plugin-gatsby (onPreBuild event)
3:58:14 PM: ────────────────────────────────────────────────────────────────
3:58:14 PM:
3:58:14 PM: No Gatsby cache found. Building fresh.
3:58:14 PM:
3:58:14 PM: Plugin "@netlify/plugin-gatsby" failed
3:58:14 PM: ────────────────────────────────────────────────────────────────
3:58:14 PM:
3:58:14 PM: Error message
3:58:14 PM: /opt/build/repo/gatsby/gatsby-config.js:1
3:58:14 PM: import dotenv from 'dotenv';
3:58:14 PM: ^^^^^^
3:58:14 PM:
3:58:14 PM: SyntaxError: Cannot use import statement outside a module
3:58:14 PM:
3:58:14 PM: Plugin details
3:58:14 PM: Package: @netlify/plugin-gatsby
3:58:14 PM: Version: 3.5.1
3:58:14 PM: Repository: git+https://github.com/netlify/netlify-plugin-gatsby.git
3:58:14 PM: npm link: https://www.npmjs.com/package/@netlify/plugin-gatsby
3:58:14 PM: Report issues: https://github.com/netlify/netlify-plugin-gatsby/issues
3:58:15 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
3:58:14 PM:
3:58:14 PM: Error location
3:58:14 PM: In "onPreBuild" event in "@netlify/plugin-gatsby" from undefined
3:58:14 PM:
3:58:14 PM: Resolved config
3:58:14 PM: build:
3:58:14 PM: base: /opt/build/repo/gatsby
3:58:14 PM: command: npm run build
3:58:14 PM: commandOrigin: ui
3:58:14 PM: environment:
3:58:14 PM: - INCOMING_HOOK_BODY
3:58:14 PM: - INCOMING_HOOK_TITLE
3:58:14 PM: - INCOMING_HOOK_URL
3:58:14 PM: publish: /opt/build/repo/gatsby/public
3:58:14 PM: publishOrigin: ui
3:58:14 PM: plugins:
3:58:14 PM: - inputs: {}
3:58:14 PM: package: '@netlify/plugin-gatsby'
3:58:15 PM: Caching artifacts
3:58:15 PM: Started saving node modules
3:58:15 PM: Finished saving node modules
3:58:15 PM: Started saving build plugins
3:58:15 PM: Finished saving build plugins
3:58:15 PM: Started saving corepack cache
3:58:15 PM: Finished saving corepack cache
3:58:15 PM: Started saving pip cache
3:58:15 PM: Finished saving pip cache
3:58:15 PM: Started saving emacs cask dependencies
3:58:15 PM: Finished saving emacs cask dependencies
3:58:15 PM: Started saving maven dependencies
3:58:15 PM: Finished saving maven dependencies
3:58:15 PM: Started saving boot dependencies
3:58:15 PM: Finished saving boot dependencies
3:58:15 PM: Started saving rust rustup cache
3:58:15 PM: Finished saving rust rustup cache
3:58:15 PM: Started saving go dependencies
3:58:15 PM: Finished saving go dependencies
3:58:15 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:58:15 PM: Failing build: Failed to build site
3:58:15 PM: Finished processing build request in 36.452s
Successful Build Log
10:24:01 AM: Build ready to start
10:24:02 AM: build-image version: 1ca34a93198b041e44214013884c57d146a23fed (focal)
10:24:02 AM: build-image tag: v4.16.4
10:24:02 AM: buildbot version: 2577a19e1559072eeb7a6727cec389b63b90401c
10:24:02 AM: Fetching cached dependencies
10:24:02 AM: Starting to download cache of 213.5MB
10:24:05 AM: Finished downloading cache in 2.177s
10:24:05 AM: Starting to extract cache
10:24:06 AM: Finished extracting cache in 1.855s
10:24:06 AM: Finished fetching cache in 4.104s
10:24:06 AM: Starting to prepare the repo for build
10:24:07 AM: Preparing Git Reference refs/heads/master
10:24:07 AM: Parsing package.json dependencies
10:24:08 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'gatsby/public' versus 'public' in the Netlify UI
10:24:08 AM: Starting build script
10:24:08 AM: Installing dependencies
10:24:08 AM: Python version set to 2.7
10:24:08 AM: Started restoring cached Node.js version
10:24:09 AM: Finished restoring cached Node.js version
10:24:10 AM: v12.18.0 is already installed.
10:24:10 AM: Now using node v12.18.0 (npm v6.14.4)
10:24:10 AM: Started restoring cached build plugins
10:24:10 AM: Finished restoring cached build plugins
10:24:10 AM: Attempting Ruby version 2.7.1, read from environment
10:24:10 AM: Started restoring cached Ruby version
10:24:10 AM: Finished restoring cached Ruby version
10:24:10 AM: Using Ruby version 2.7.1
10:24:10 AM: Using PHP version 8.0
10:24:10 AM: Started restoring cached corepack dependencies
10:24:10 AM: mv: cannot move '/opt/build/cache/.node/corepack' to '/opt/buildhome/.node/corepack': No such file or directory
10:24:10 AM: Finished restoring cached corepack dependencies
10:24:10 AM: No npm workspaces detected
10:24:10 AM: Started restoring cached node modules
10:24:10 AM: Finished restoring cached node modules
10:24:10 AM: Bypassing sha validation. Running pre & post install scripts
10:24:11 AM: Installing npm packages using npm version 6.14.4
10:24:17 AM: npm WARN @splidejs/react-splide@0.4.4 requires a peer of react@16.13.1 but none is installed. You must install peer dependencies yourself.
10:24:17 AM: npm WARN @splidejs/react-splide@0.4.4 requires a peer of react-dom@16.13.1 but none is installed. You must install peer dependencies yourself.
10:24:17 AM: npm WARN express-graphql@0.9.0 requires a peer of graphql@^14.4.1 but none is installed. You must install peer dependencies yourself.
10:24:17 AM: npm WARN slick-carousel@1.8.1 requires a peer of jquery@>=1.8.0 but none is installed. You must install peer dependencies yourself.
10:24:17 AM: npm WARN ts-node@9.1.1 requires a peer of typescript@>=2.7 but none is installed. You must install peer dependencies yourself.
10:24:17 AM: npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
10:24:17 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
10:24:17 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:24:17 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
10:24:17 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:24:17 AM: audited 2517 packages in 6.319s
10:24:18 AM: 221 packages are looking for funding
10:24:18 AM: run `npm fund` for details
10:24:18 AM: found 322 vulnerabilities (10 low, 131 moderate, 146 high, 35 critical)
10:24:18 AM: run `npm audit fix` to fix them, or `npm audit` for details
10:24:18 AM: npm packages installed
10:24:18 AM: Started restoring cached go cache
10:24:18 AM: Finished restoring cached go cache
10:24:18 AM: Installing Go version 1.14.4 (requested 1.14.4)
10:24:22 AM: unset GOOS;
10:24:22 AM: unset GOARCH;
10:24:22 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.14.4.linux.amd64';
10:24:22 AM: export PATH="/opt/buildhome/.gimme/versions/go1.14.4.linux.amd64/bin:${PATH}";
10:24:22 AM: go version >&2;
10:24:22 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.14.4.linux.amd64.env"
10:24:22 AM: go version go1.14.4 linux/amd64
10:24:22 AM: Detected 1 framework(s)
10:24:22 AM: "gatsby" at version "3.4.0"
10:24:22 AM: Installing missing commands
10:24:22 AM: Verify run directory
10:24:22 AM: Section completed: initializing
10:24:23 AM:
10:24:23 AM: Netlify Build
10:24:23 AM: ────────────────────────────────────────────────────────────────
10:24:23 AM:
10:24:23 AM: ❯ Version
10:24:23 AM: @netlify/build 29.5.1
10:24:23 AM:
10:24:23 AM: ❯ Flags
10:24:23 AM: baseRelDir: true
10:24:23 AM: buildId: 63d068911279db538b5362b3
10:24:23 AM: deployId: 63d068911ce62d000844de55
10:24:23 AM:
10:24:23 AM: ❯ Current directory
10:24:23 AM: /opt/build/repo/gatsby
10:24:23 AM:
10:24:23 AM: ❯ Config file
10:24:23 AM: No config file was defined: using default values.
10:24:23 AM:
10:24:23 AM: ❯ Context
10:24:23 AM: production
10:24:23 AM:
10:24:23 AM: 1. Build command from Netlify app
10:24:23 AM: ────────────────────────────────────────────────────────────────
10:24:23 AM:
10:24:23 AM: $ npm run build
10:24:24 AM: > example@0.1.0 build /opt/build/repo/gatsby
10:24:24 AM: > cross-env NODE_OPTIONS="-r esm" gatsby build
10:24:29 AM: success open and validate gatsby-configs - 0.041s
10:24:30 AM: success load plugins - 1.203s
10:24:30 AM: success onPreInit - 0.022s
10:24:30 AM: success initialize cache - 0.003s
10:24:30 AM: success copy gatsby files - 0.036s
10:24:30 AM: warning [sanity] Using `watchMode` when not in develop mode might prevent your build from completing
10:24:30 AM: info [sanity] Fetching remote GraphQL schema
10:24:31 AM: info [sanity] Transforming to Gatsby-compatible GraphQL SDL
10:24:31 AM: info [sanity] Stitching GraphQL schemas from SDL
10:24:31 AM: success onPreBootstrap - 0.319s
10:24:31 AM: success createSchemaCustomization - 0.010s
10:24:31 AM: info [sanity] Fetching export stream for dataset
10:24:34 AM: info [sanity] Watch mode enabled, starting a listener
10:24:35 AM: info [sanity] Done! Exported 2190 documents.
10:24:35 AM: success Checking for changed pages - 0.000s
10:24:35 AM: success source and transform nodes - 3.811s
10:24:35 AM: success building schema - 0.672s
10:24:36 AM: success createPages - 0.101s
10:24:36 AM: success createPagesStatefully - 0.051s
10:24:36 AM: info Total nodes: 2302, SitePage nodes: 72 (use --verbose for breakdown)
10:24:36 AM: success Checking for changed pages - 0.000s
10:24:36 AM: success update schema - 0.126s
10:24:36 AM: success onPreExtractQueries - 0.002s
10:24:37 AM: success extract queries from components - 1.462s
10:24:37 AM: success write out redirect data - 0.001s
10:24:37 AM: success Build manifest and related icons - 0.033s
10:24:37 AM: success onPostBootstrap - 0.034s
10:24:37 AM: info bootstrap finished - 13.668s
10:24:37 AM: success run static queries - 0.007s - 1/1 143.13/s
10:24:38 AM: success run page queries - 0.522s - 71/71 135.98/s
10:24:38 AM: success write out requires - 0.003s
10:24:38 AM: STAGE:: build-javascript
10:24:39 AM: warning Browserslist: caniuse-lite is outdated. Please run:
10:24:39 AM: npx browserslist@latest --update-db
10:24:39 AM: Why you should do it regularly:
10:24:39 AM: https://github.com/browserslist/browserslist#browsers-data-updating
10:24:54 AM: Browserslist: caniuse-lite is outdated. Please run:
10:24:54 AM: npx browserslist@latest --update-db
10:24:54 AM: Why you should do it regularly:
10:24:54 AM: https://github.com/browserslist/browserslist#browsers-data-updating
10:24:57 AM: warning Css Minimizer Plugin: cssnano: /opt/build/repo/gatsby/styles.6513ce135ed6876845a3.css:613:5: Error in parsing SVG: Non-whitespace before first tag.
10:24:57 AM: Line: 0
10:24:57 AM: Column: 1
10:24:57 AM: Char: d
10:24:57 AM: warning Css Minimizer Plugin: cssnano: /opt/build/repo/gatsby/styles.6513ce135ed6876845a3.css:613:5: Error in parsing SVG: Non-whitespace before first tag.
10:24:57 AM: Line: 0
10:24:57 AM: Column: 1
10:24:57 AM: Char: d
10:24:57 AM: warning Css Minimizer Plugin: cssnano: /opt/build/repo/gatsby/styles.6513ce135ed6876845a3.css:613:5: Error in parsing SVG: Non-whitespace before first tag.
10:24:57 AM: Line: 0
10:24:57 AM: Column: 1
10:24:57 AM: Char: d
10:24:57 AM: success Building production JavaScript and CSS bundles - 18.881s
10:24:57 AM: success Rewriting compilation hashes - 0.001s
10:24:57 AM: STAGE:: build-html
10:25:00 AM: success Building HTML renderer - 3.179s
10:25:01 AM: success Building static HTML for pages - 1.017s - 71/71 69.82/s
10:25:01 AM: success onPostBuild - 0.027s
10:25:01 AM: info Done building in 37.599843229 sec
10:25:02 AM:
10:25:02 AM: (build.command completed in 38.3s)
10:25:02 AM:
10:25:02 AM: 2. Deploy site
10:25:02 AM: ────────────────────────────────────────────────────────────────
10:25:02 AM:
10:25:02 AM: Starting to deploy site from 'gatsby/public'
10:25:02 AM: Calculating files to upload
10:25:02 AM: 0 new files to upload
10:25:02 AM: 0 new functions to upload
10:25:02 AM: Section completed: deploying
10:25:02 AM: Site deploy was successfully initiated
10:25:02 AM:
10:25:02 AM: (Deploy site completed in 378ms)
10:25:02 AM:
10:25:02 AM: Netlify Build Complete
10:25:02 AM: ────────────────────────────────────────────────────────────────
10:25:02 AM:
10:25:02 AM: (Netlify Build completed in 38.7s)
10:25:02 AM: Caching artifacts
10:25:02 AM: Started saving node modules
10:25:02 AM: Finished saving node modules
10:25:02 AM: Started saving build plugins
10:25:02 AM: Finished saving build plugins
10:25:02 AM: Started saving pip cache
10:25:02 AM: Finished saving pip cache
10:25:02 AM: Started saving emacs cask dependencies
10:25:03 AM: Finished saving emacs cask dependencies
10:25:03 AM: Started saving maven dependencies
10:25:03 AM: Finished saving maven dependencies
10:25:03 AM: Started saving boot dependencies
10:25:03 AM: Finished saving boot dependencies
10:25:03 AM: Started saving rust rustup cache
10:25:03 AM: Finished saving rust rustup cache
10:25:03 AM: Started saving go dependencies
10:25:03 AM: Finished saving go dependencies
10:25:03 AM: Build script success
10:25:03 AM: Section completed: building
10:25:04 AM: Starting post processing
10:25:04 AM: Post processing - HTML
10:25:04 AM: Uploading Cache of size 215.1MB
10:25:04 AM: Post processing - header rules
10:25:05 AM: Post processing - redirect rules
10:25:05 AM: Post processing done
10:25:05 AM: Section completed: postprocessing
10:25:05 AM: Site is live ✨
10:25:06 AM: Section completed: cleanup
10:25:06 AM: Finished processing build request in 1m3.872s
Function logs
Function logs
# Paste logs here
Hi @Crowl3y
Can you try following to disable automatic installation:
- Go to Site Settings -> Build & deploy
- In Build Settings there probably is now
Runtime: Gatsby
:
- Edit Settings and you should be able to remove / unselect Gatsby
I will be looking to fix the problem but above should be viable workaround
Hi @pieh, thanks for the quick response. I went into Build Settings and there was no runtime set, so no-go sorry :/
Ah, I don't have context around other ways to disable the plugin unfortunately. I did prepare a potential fix for your scenario in #562