Next.js build is failing on plugin v4.33.0

I opened a new PR to our dev environment today and the build quickly failed with an “Internal plugin error”. Looking at the log, I see that there is a new version of @netlify/plugin-nextjs and there is a ticket in that plugin’s Github repo that is very similar to ours. I added details of what we’re encountering there: Build Error - Plugin "@netlify/plugin-nextjs" internal error · Issue #2024 · netlify/next-runtime · GitHub, but the full log is:

4:24:16 PM: build-image version: 6c82004ef0368b3a0232c6837cead23188bb347e (focal)
4:24:16 PM: buildbot version: 47d1e6bf5eecb8879b17d173eab0e8dc3ea1b589
4:24:16 PM: Building without cache
4:24:16 PM: Starting to prepare the repo for build
4:24:17 PM: No cached dependencies found. Cloning fresh repo
4:24:17 PM: git clone --filter=blob:none https://github.com/OfficialMetrie/metrie.com
4:24:17 PM: Preparing Git Reference refs/heads/dev
4:24:20 PM: Parsing package.json dependencies
4:24:21 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'site/.next' versus '.next' in the Netlify UI
4:24:21 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'site/netlify/functions' versus 'netlify/functions' in the Netlify UI
4:24:22 PM: Starting to install dependencies
4:24:22 PM: Attempting Node.js version 'v16.13.2' from .nvmrc
4:24:22 PM: Downloading and installing node v16.13.2...
4:24:22 PM: Downloading https://nodejs.org/dist/v16.13.2/node-v16.13.2-linux-x64.tar.xz...
4:24:23 PM: Computing checksum with sha256sum
4:24:23 PM: Checksums matched!
4:24:25 PM: Now using node v16.13.2 (npm v8.1.2)
4:24:25 PM: Enabling Node.js Corepack
4:24:25 PM: Started restoring cached build plugins
4:24:25 PM: Finished restoring cached build plugins
4:24:25 PM: Started restoring cached corepack dependencies
4:24:25 PM: Finished restoring cached corepack dependencies
4:24:25 PM: No npm workspaces detected
4:24:25 PM: Started restoring cached node modules
4:24:25 PM: Finished restoring cached node modules
4:24:25 PM: Installing npm packages using npm version 8.1.2
4:24:27 PM: added 2484 packages in 2s
4:24:27 PM: 303 packages are looking for funding
4:24:27 PM:   run `npm fund` for details
4:24:27 PM: npm packages installed
4:24:27 PM: Python version set to 3.8
4:24:27 PM: Using PHP version 8.0
4:24:28 PM: Attempting Ruby version 2.7.2, read from environment
4:24:28 PM: Using Ruby version 2.7.2
4:24:29 PM: Started restoring cached go cache
4:24:29 PM: Finished restoring cached go cache
4:24:29 PM: Installing Go version 1.19.5 (requested 1.19.5)
4:24:34 PM: go version go1.19.5 linux/amd64
4:24:35 PM: Install dependencies script success
4:24:35 PM: Starting build script
4:24:35 PM: Using stage install dependencies
4:24:35 PM: Detected 1 framework(s)
4:24:35 PM: "next" at version "unknown"
4:24:35 PM: Section completed: initializing
4:24:37 PM: ​
4:24:37 PM:   Netlify Build                                                 
4:24:37 PM: ────────────────────────────────────────────────────────────────
4:24:37 PM: ​
4:24:37 PM: ❯ Version
4:24:37 PM:   @netlify/build 29.9.0
4:24:37 PM: ​
4:24:37 PM: ❯ Flags
4:24:37 PM:   baseRelDir: true
4:24:37 PM:   buildId: 642b35e66b64da760f6f7791
4:24:37 PM:   deployId: 642b35e66b64da760f6f7793
4:24:37 PM: ​
4:24:37 PM: ❯ Current directory
4:24:37 PM:   /opt/build/repo/site
4:24:37 PM: ​
4:24:37 PM: ❯ Config file
4:24:37 PM:   No config file was defined: using default values.
4:24:37 PM: ​
4:24:37 PM: ❯ Context
4:24:37 PM:   production
4:24:37 PM: ​
4:24:37 PM: ❯ Installing plugins
4:24:37 PM:    - @netlify/plugin-nextjs@4.33.0
4:24:46 PM: ​
4:24:46 PM: ❯ Using Next.js Runtime - v4.33.0
4:24:47 PM: ​
4:24:47 PM:   Plugin "@netlify/plugin-nextjs" internal error                
4:24:47 PM: ────────────────────────────────────────────────────────────────
4:24:47 PM: ​
4:24:47 PM:   Error message
4:24:47 PM:   Could not import plugin:
4:24:47 PM:   Error: Could not find Next.js server
4:24:47 PM: ​
4:24:47 PM:   Plugin details
4:24:47 PM:   Package:        @netlify/plugin-nextjs
4:24:47 PM:   Version:        4.33.0
4:24:47 PM:   Repository:     git+https://github.com/netlify/next-runtime.git
4:24:47 PM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
4:24:47 PM:   Report issues:  https://github.com/netlify/next-runtime/issues
4:24:47 PM: ​
4:24:47 PM:   Error location
4:24:47 PM:   While loading "@netlify/plugin-nextjs" from Netlify app
4:24:47 PM:       at getNextServer (/opt/build/repo/site/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/templates/handlerUtils.js:169:19)
4:24:47 PM:       at Object.<anonymous> (/opt/build/repo/site/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/templates/server.js:5:53)
4:24:47 PM:       at Module._compile (node:internal/modules/cjs/loader:1196:14)
4:24:47 PM:       at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
4:24:47 PM:       at Module.load (node:internal/modules/cjs/loader:1074:32)
4:24:47 PM:       at Function.Module._load (node:internal/modules/cjs/loader:909:12)
4:24:47 PM:       at Module.require (node:internal/modules/cjs/loader:1098:19)
4:24:47 PM:       at require (node:internal/modules/cjs/helpers:108:18)
4:24:47 PM:       at Object.<anonymous> (/opt/build/repo/site/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/templates/getHandler.js:14:31)
4:24:47 PM:       at Module._compile (node:internal/modules/cjs/loader:1196:14)
4:24:47 PM: ​
4:24:47 PM:   Resolved config
4:24:47 PM:   build:
4:24:47 PM:     base: /opt/build/repo/site
4:24:47 PM:     command: NODE_OPTIONS=--max_old_space_size=4096 npm ci && npm run build
4:24:47 PM:     commandOrigin: ui
4:24:48 PM: Failed during stage 'building site': Build script returned non-zero exit code: 3 (https://ntl.fyi/exit-code-3)
4:24:47 PM:     environment:
4:24:47 PM:       - ALGOLIA_API_KEY
4:24:47 PM:       - ALGOLIA_APP_ID
4:24:47 PM:       - API_BASE
4:24:47 PM:       - API_PREVIEW_TOKEN
4:24:47 PM:       - BLOG_ARTICLES_INDEX_ID
4:24:47 PM:       - CATALOGS_INDEX_ID
4:24:47 PM:       - CONTENTFUL_ACCESS_TOKEN
4:24:47 PM:       - CONTENTFUL_ALGOLIA_UPDATE_KEY
4:24:47 PM:       - CONTENTFUL_ENVIRONMENT
4:24:47 PM:       - CONTENTFUL_MANAGEMENT_ACCESS_TOKEN
4:24:47 PM:       - CONTENTFUL_PREVIEW_ACCESS_TOKEN
4:24:47 PM:       - CONTENTFUL_SPACE_ID
4:24:47 PM:       - ENVIRONMENT
4:24:47 PM:       - FACETS_INDEX_ID
4:24:47 PM:       - GOOGLE_API
4:24:47 PM:       - GOOGLE_GEOCODING_API_KEY
4:24:47 PM:       - GOOGLE_GEOCODING_URL
4:24:47 PM:       - GTM_AUTH
4:24:47 PM:       - GTM_PREVIEW
4:24:47 PM:       - HUBSPOT_API_KEY
4:24:47 PM:       - LOCATIONS_INDEX_ID
4:24:47 PM:       - NETLIFY_GRAPH_TOKEN
4:24:47 PM:       - NEXT_DISABLE_NETLIFY_EDGE
4:24:47 PM:       - NEXT_PUBLIC_GOOGLE_API
4:24:47 PM:       - NODE_VERSION
4:24:47 PM:       - NPM_FLAGS
4:24:47 PM:       - ONEGRAPH_AUTHLIFY_TOKEN
4:24:47 PM:       - PAGES_INDEX_ID
4:24:47 PM:       - PIM_EXPORT_URL
4:24:47 PM:       - POSITIONSTACK_API_KEY
4:24:47 PM:       - POSITIONSTACK_URL
4:24:47 PM:       - PRODUCTS_INDEX_ID
4:24:47 PM:       - SITE_BASE
4:24:47 PM:     publish: /opt/build/repo/site/.next
4:24:47 PM:     publishOrigin: ui
4:24:47 PM:   functionsDirectory: /opt/build/repo/site/netlify/functions
4:24:47 PM:   plugins:
4:24:47 PM:     - inputs: {}
4:24:47 PM:       origin: ui
4:24:47 PM:       package: '@netlify/plugin-nextjs'
4:24:48 PM: Caching artifacts
4:24:48 PM: Started saving node modules
4:24:48 PM: Finished saving node modules
4:24:48 PM: Started saving build plugins
4:24:48 PM: Finished saving build plugins
4:24:48 PM: Started saving corepack cache
4:24:48 PM: Finished saving corepack cache
4:24:48 PM: Started saving pip cache
4:24:48 PM: Finished saving pip cache
4:24:48 PM: Started saving emacs cask dependencies
4:24:48 PM: Finished saving emacs cask dependencies
4:24:48 PM: Started saving maven dependencies
4:24:48 PM: Finished saving maven dependencies
4:24:48 PM: Started saving boot dependencies
4:24:48 PM: Finished saving boot dependencies
4:24:48 PM: Started saving rust rustup cache
4:24:48 PM: Finished saving rust rustup cache
4:24:48 PM: Started saving go dependencies
4:24:48 PM: Finished saving go dependencies
4:24:48 PM: Build failed due to a plugin error: Build script returned non-zero exit code: 3
4:24:48 PM: Failing build: Failed to build site
4:24:49 PM: Finished processing build request in 32.239s

I compared this to similar logs from last week (which ran on plugin version v4.29.3), and one early notable difference is this line:

4:24:35 PM: "next" at version "unknown"

(previously this said)

4:32:25 PM: "next" at version "12.3.4"

We had other plugin issues in the past and were able to work around them by specifying a plugin version in package.json, but that did not seem to work for me in a deploy preview. I also attempted to find the area of the Netlify site config where we could specify the plugin version to use, and it seems to have been removed.

Hi @daverodriguez, thanks for the post.

Kindly visit the Netlify Forum link below and follow the suggestion there as the problem similar to your problem.

Let me know the outcome.

Thanks.

Hello,

I did try this, but I’m having trouble getting Netlify to use the package version specified in my package.json.

Here’s the relevant bit:

    "devDependencies": {
        "@netlify/plugin-nextjs": "4.32.2",
        "@babel/core": "^7.16.0",
        ...

But I get the following output from Netlify, even after clearing cache and deploying:

9:27:02 AM: ❯ Using Next.js Runtime - v4.33.0
9:27:03 AM: ​
9:27:03 AM:   Plugin "@netlify/plugin-nextjs" internal error                
9:27:03 AM: ────────────────────────────────────────────────────────────────
9:27:03 AM: ​
9:27:03 AM:   Error message
9:27:03 AM:   Could not import plugin:
9:27:03 AM:   Error: Could not find Next.js server
9:27:03 AM: ​
9:27:03 AM:   Plugin details
9:27:03 AM:   Package:        @netlify/plugin-nextjs
9:27:03 AM:   Version:        4.33.0
9:27:03 AM:   Repository:     git+https://github.com/netlify/next-runtime.git
9:27:03 AM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
9:27:03 AM:   Report issues:  https://github.com/netlify/next-runtime/issues

As I said above, there used to be an area in the Netlify UI where we could manually specify the package version, but things seem to have been reorganized and we’re unable to find it now.

Hi @daverodriguez, thanks for the additional feedback. Kindly add NETLIFY_NEXT_PLUGIN_SKIP environment variable with the value true in Netlify UI to see if it works.

Check the link below on how to set environment variable on the Netlify UI

Thanks.

This may have done something, but it still didn’t work.

In the current PR / deploy preview, it had no effect.

The build still tried to use plugin version 4.33.0 and failed.

I opened up a new PR, with the environment variable set, and the build succeeded. It attempted to use 4.29.3.

3:08:24 PM: ❯ Using Next.js Runtime - v4.29.3
3:08:24 PM: ​
3:08:24 PM: ❯ Outdated plugins
3:08:24 PM:    - @netlify/plugin-nextjs@4.29.3: latest version is 4.33.0
3:08:24 PM:      To upgrade this plugin, please update its version in "package.json"

However, after build, the site did not contain our content. Instead, I see this:
https://deploy-preview-682--metrie-dev.netlify.app/

image

After setting the NETLIFY_NEXT_PLUGIN_SKIP variable back to false, the build for this new branch is now trying to use v4.33.0 and failing to build again.

Hi @daverodriguez, thanks for the extra feedback.
The reason for the page not found page is because your base directory might not be properly configured.

If your project is within a sub-directory called site then set your base directory to site. Else leave it unset.
Also not that the settings in your netlify.toml file with take precedence over other settings.

Thanks.

I noticed that error as well. Here’s what we have in the Netlify UI:

This configuration has not changed for months and has been publishing successfully until this week.

We also do not have an explicit netlify.toml file in our project - we haven’t needed one as we’ve been able to do what we need through the Netlify UI.

Hi @daverodriguez.

Since you stated you have been publishing successfully for weeks it’s possible one of your deployments caused the issue.

If possible can you share the repository of the site for me to help with the debugging.

Thanks.

Of course! It’s a private repository, but I can share access with your Github username.

There’s maintenance going on all the time, but we have tried to redeploy code that deployed fine last week, and the only difference is the plugin version. Our staging environment, with the same code, deploys fine on plugin v4.29.3. In my mind, the major issue to be solved here is why we haven’t been successful telling our dev environment to use an older plugin version.

1 Like

Hi @daverodriguez :wave:t6: , I sent your query to our helpdesk. Our team will follow up with you via email ASAP.

1 Like

Replying to this thread as we have a partial solve. I believe there’s still an issue with plugin v4.33.0, but we found two settings in our configuration that were causing our project to not install the correct plugin version as specified in our package.json.

We found and removed the following environment variable:

NPM_FLAGS: --dry-run

As well as changing our build command (which had apparently been tweaked recently) from:

NODE_OPTIONS=--max_old_space_size=4096 npm ci && npm run build

to

NODE_OPTIONS=--max_old_space_size=4096 npm run build

We were then able to downgrade our package.json to reference plugin version 4.32.2 and build successfully in our dev environment.