NextJS Plugin Error

Build problems when I upgraded NextJS and other reps recently. I already tried deleting and reinstalling the plugin.

https://nextweather.netlify.app

Screenshot of build settings: Build & deploy | Site settings

12:03:07 PM: Build ready to start
12:03:09 PM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
12:03:09 PM: build-image tag: v4.10.1
12:03:09 PM: buildbot version: 7e449fda4d95fa42451b88186ca7054116649237
12:03:09 PM: Building without cache
12:03:09 PM: Starting to prepare the repo for build
12:03:09 PM: No cached dependencies found. Cloning fresh repo
12:03:09 PM: git clone GitHub - ivanoats/nextweather: Weather station data focused on wind and tide for human powered watercraft
12:03:10 PM: Preparing Git Reference refs/heads/main
12:03:10 PM: Parsing package.json dependencies
12:03:11 PM: Starting build script
12:03:11 PM: Installing dependencies
12:03:11 PM: Python version set to 2.7
12:03:12 PM: Downloading and installing node v12.18.0…
12:03:12 PM: Downloading https://nodejs.org/dist/v12.18.0/node-v12.18.0-linux-x64.tar.xz…

12:03:12 PM: Computing checksum with sha256sum

12:03:12 PM: Checksums matched!

12:03:15 PM: Now using node v12.18.0 (npm v6.14.4)

12:03:15 PM: Started restoring cached build plugins

12:03:15 PM: Finished restoring cached build plugins

12:03:15 PM: Attempting ruby version 2.7.2, read from environment

12:03:15 PM: Using ruby version 2.7.2

12:03:16 PM: Using PHP version 8.0

12:03:16 PM: No npm workspaces detected

12:03:16 PM: Started restoring cached node modules

12:03:16 PM: Finished restoring cached node modules

12:03:16 PM: Installing NPM modules using NPM version 6.14.4

… skipping WARNs due to limit on forum post chars …

12:04:12 PM: > core-js@3.25.2 postinstall /opt/build/repo/node_modules/core-js

12:04:12 PM: > node -e β€œtry{require(β€˜./postinstall’)}catch(e){}”

12:04:12 PM: > core-js-pure@3.25.2 postinstall /opt/build/repo/node_modules/core-js-pure

12:04:12 PM: > node -e β€œtry{require(β€˜./postinstall’)}catch(e){}”

12:04:14 PM: > cypress@10.8.0 postinstall /opt/build/repo/node_modules/cypress

12:04:14 PM: > node index.js --exec install

12:04:15 PM: Note: Overriding Cypress cache directory to: ./node_modules/.cache/CypressBinary

12:04:15 PM: Previous installs of Cypress may not be found.

12:04:15 PM: Installing Cypress (version: 10.8.0)

12:04:15 PM: [STARTED] Task without title.

12:04:17 PM: [SUCCESS] Task without title.

12:04:17 PM: [STARTED] Task without title.

12:04:22 PM: [SUCCESS] Task without title.

12:04:22 PM: [STARTED] Task without title.

12:04:22 PM: [SUCCESS] Task without title.

12:04:23 PM: You can now open Cypress by running: node_modules/.bin/cypress open

12:04:23 PM: Installing Cypress | Cypress Documentation

12:04:24 PM: npm notice created a lockfile as package-lock.json. You should commit this file.

…skipping more WARN…

12:04:24 PM: added 2368 packages from 924 contributors and audited 2388 packages in 67.152s

12:04:25 PM: 275 packages are looking for funding

12:04:25 PM: run npm fund for details

12:04:25 PM: found 11 high severity vulnerabilities

12:04:25 PM: run npm audit fix to fix them, or npm audit for details

12:04:25 PM: NPM modules installed

12:04:25 PM: Started restoring cached go cache

12:04:25 PM: Finished restoring cached go cache

12:04:25 PM: Installing Go version 1.14.4 (requested 1.14.4)

12:04:29 PM: unset GOOS;

12:04:29 PM: unset GOARCH;

12:04:29 PM: export GOROOT=β€˜/opt/buildhome/.gimme/versions/go1.14.4.linux.amd64’;

12:04:29 PM: export PATH=β€œ/opt/buildhome/.gimme/versions/go1.14.4.linux.amd64/bin:${PATH}”;

12:04:29 PM: go version >&2;

12:04:29 PM: export GIMME_ENV=β€œ/opt/buildhome/.gimme/env/go1.14.4.linux.amd64.env”

12:04:29 PM: go version go1.14.4 linux/amd64

12:04:29 PM: Installing missing commands

12:04:29 PM: Verify run directory

12:04:30 PM: ​

12:04:30 PM: ────────────────────────────────────────────────────────────────

12:04:30 PM: Netlify Build

12:04:30 PM: ────────────────────────────────────────────────────────────────

12:04:30 PM: ​

12:04:30 PM: ❯ Version

12:04:30 PM: @netlify/build 27.18.1

12:04:30 PM: ​

12:04:30 PM: ❯ Flags

12:04:30 PM: baseRelDir: true

12:04:30 PM: buildId: 63276b6bc1fda76addd5fd89

12:04:30 PM: deployId: 63276b6bc1fda76addd5fd8b

12:04:30 PM: ​

12:04:30 PM: ❯ Current directory

12:04:30 PM: /opt/build/repo

12:04:30 PM: ​

12:04:30 PM: ❯ Config file

12:04:30 PM: No config file was defined: using default values.

12:04:30 PM: ​

12:04:30 PM: ❯ Context

12:04:30 PM: production

12:04:30 PM: ​

12:04:30 PM: ❯ Installing plugins

12:04:30 PM: - @netlify/plugin-nextjs@4.22.0

12:04:46 PM: ​

12:04:46 PM: ❯ Using Next.js Runtime - v4.22.0

12:04:47 PM: ​

12:04:47 PM: ────────────────────────────────────────────────────────────────

12:04:47 PM: 1. @netlify/plugin-nextjs (onPreBuild event)

12:04:47 PM: ────────────────────────────────────────────────────────────────

12:04:47 PM: ​

12:04:47 PM: No Next.js cache to restore.

12:04:47 PM: Netlify configuration property β€œbuild.environment.NEXT_PRIVATE_TARGET” value changed.

12:04:47 PM: ​

12:04:47 PM: (@netlify/plugin-nextjs onPreBuild completed in 22ms)

12:04:47 PM: ​

12:04:47 PM: ────────────────────────────────────────────────────────────────

12:04:47 PM: 2. Build command from Netlify app

12:04:47 PM: ────────────────────────────────────────────────────────────────

12:04:47 PM: ​

12:04:47 PM: $ npm run build

12:04:48 PM: > nextweather@0.2.4 build /opt/build/repo

12:04:48 PM: > next build

12:04:48 PM: (node:1745) ExperimentalWarning: The ESM module loader is experimental.

12:04:48 PM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: no-cache | Next.js

12:04:48 PM: info - Linting and checking validity of types…

12:04:52 PM: info - Creating an optimized production build…

12:05:02 PM: info - Compiled successfully

12:05:02 PM: info - Collecting page data…

12:05:03 PM: /opt/build/repo/node_modules/@chakra-ui/accordion/dist/index.cjs.js:136

12:05:03 PM: return defaultIndex ?? ;

12:05:03 PM: ^

12:05:03 PM: SyntaxError: Unexpected token β€˜?’

12:05:03 PM: at wrapSafe (internal/modules/cjs/loader.js:1054:16)

12:05:03 PM: at Module._compile (internal/modules/cjs/loader.js:1102:27)

12:05:03 PM: at Object.Module._extensions…js (internal/modules/cjs/loader.js:1158:10)

12:05:03 PM: at Module.load (internal/modules/cjs/loader.js:986:32)

12:05:03 PM: at Function.Module._load (internal/modules/cjs/loader.js:879:14)

12:05:03 PM: at Module.require (internal/modules/cjs/loader.js:1026:19)

12:05:03 PM: at require (internal/modules/cjs/helpers.js:72:18)

12:05:03 PM: at Object. (/opt/build/repo/node_modules/@chakra-ui/react/dist/index.cjs.js:41:25)

12:05:03 PM: at Module._compile (internal/modules/cjs/loader.js:1138:30)

12:05:03 PM: at Object.Module._extensions…js (internal/modules/cjs/loader.js:1158:10)

12:05:03 PM: > Build error occurred

12:05:03 PM: Error: Failed to collect page data for /

12:05:03 PM: at /opt/build/repo/node_modules/next/dist/build/utils.js:771:15

12:05:03 PM: at processTicksAndRejections (internal/process/task_queues.js:97:5) {

12:05:03 PM: type: β€˜Error’

12:05:03 PM: }

12:05:03 PM: npm ERR! code ELIFECYCLE

12:05:03 PM: npm ERR! errno 1

12:05:03 PM: npm ERR! nextweather@0.2.4 build: next build

12:05:03 PM: npm ERR! Exit status 1

12:05:03 PM: npm ERR!

12:05:03 PM: npm ERR! Failed at the nextweather@0.2.4 build script.

12:05:03 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

12:05:03 PM: npm ERR! A complete log of this run can be found in:

12:05:03 PM: npm ERR! /opt/buildhome/.npm/_logs/2022-09-18T19_05_03_200Z-debug.log

12:05:03 PM: ​

12:05:03 PM: ────────────────────────────────────────────────────────────────

12:05:03 PM: β€œbuild.command” failed

12:05:03 PM: ────────────────────────────────────────────────────────────────

12:05:03 PM: ​

12:05:03 PM: Error message

12:05:03 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)

12:05:03 PM: ​

12:05:03 PM: Error location

12:05:03 PM: In Build command from Netlify app:

12:05:03 PM: npm run build

12:05:03 PM: ​

12:05:03 PM: Resolved config

12:05:03 PM: build:

12:05:03 PM: command: npm run build

12:05:03 PM: commandOrigin: ui

12:05:03 PM: environment:

12:05:03 PM: - NEXT_PRIVATE_TARGET

12:05:03 PM: publish: /opt/build/repo/.next

12:05:03 PM: publishOrigin: ui

12:05:03 PM: plugins:

12:05:03 PM: - inputs: {}

12:05:03 PM: origin: ui

12:05:03 PM: package: β€˜@netlify/plugin-nextjs’

12:05:03 PM: Caching artifacts

12:05:03 PM: Started saving node modules

12:05:03 PM: Finished saving node modules

12:05:03 PM: Started saving build plugins

12:05:03 PM: Finished saving build plugins

12:05:03 PM: Started saving pip cache

12:05:03 PM: Finished saving pip cache

12:05:03 PM: Started saving emacs cask dependencies

12:05:03 PM: Finished saving emacs cask dependencies

12:05:03 PM: Started saving maven dependencies

12:05:03 PM: Finished saving maven dependencies

12:05:03 PM: Started saving boot dependencies

12:05:03 PM: Finished saving boot dependencies

12:05:03 PM: Started saving rust rustup cache

12:05:03 PM: Finished saving rust rustup cache

12:05:03 PM: Started saving go dependencies

12:05:03 PM: Finished saving go dependencies

12:05:04 PM: Build failed due to a user error: Build script returned non-zero exit code: 2

12:05:04 PM: Creating deploy upload records

12:05:04 PM: Failing build: Failed to build site

12:05:05 PM: Failed during stage β€˜building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)

12:05:05 PM: Finished processing build request in 1m55.429072011s

Hi, @ivanoats. This shows the build using Node version 12.18.0:

12:03:15 PM: Now using node v12.18.0 (npm v6.14.4)

However, Next.js itself requires at least 12.22.0 according to this page:

https://nextjs.org/docs/upgrading#upgrading-from-11-to-12

Have you tried upgrading to a newer version of Node.js?

I’m just using the default Netlify build settings. How would I upgrade node on Netlify’s servers?

Hi @ivanoats,

You can choose the Node.js version by following this Netlify Doc:

Let us know if you have any questions.

1 Like

Thank you, adding a .nvmrc file with lts/* solved the issue.

1 Like