netlify / next-runtime

The Next.js Runtime allows Next.js to run on Netlify with zero configuration
https://www.npmjs.com/package/@netlify/plugin-nextjs
651 stars 86 forks source link

[Bug]: NETLIFY_NEXT_PLUGIN_SKIP no longer works in v5 #2458

Closed cfhull closed 5 months ago

cfhull commented 5 months ago

Summary

Sites that have been updated to the Next runtime v5 are no longer respecting the NETLIFY_NEXT_PLUGIN_SKIP environment variable, causing static export builds to fail. As a workaround, removing the runtime through the Netlify UI allows the build to complete.

A link to a reproduction repository

https://github.com/cfhull/static-export

Expected Result

Having the NETLIFY_NEXT_PLUGIN_SKIP env var configured should allow static export builds to succeed

Actual Result

The NETLIFY_NEXT_PLUGIN_SKIP env var is being ignored, and builds are no longer working.

Steps to reproduce

Run a static export build in netlify with the next runtime v5

Next Runtime version

5.1.0

Is your issue related to the app directory?

More information about your build

What OS are you using?

None

Your netlify.toml file

`netlify.toml` ```toml # Paste content of your `netlify.toml` file here ```

Your public/_redirects file

No response

Your next.config.js file

`next.config.js` ```js /** @type {import('next').NextConfig} */ const nextConfig = { output: "export", images: { unoptimized: true }, reactStrictMode: true, swcMinify: true, webpack: (config) => { config.infrastructureLogging = { level: "error", }; return config; }, }; export default nextConfig; ```

Builds logs (or link to your logs)

Build logs ``` 1:47:35 PM: build-image version: fcb0c1b3ada6d25c1cb58e8bc514f5f23cc14f15 (focal) 1:47:35 PM: buildbot version: ee2ef905a4bdb64f7733dd60a718aa00319e6f82 1:47:35 PM: Fetching cached dependencies 1:47:35 PM: Starting to download cache of 590.5MB 1:47:39 PM: Finished downloading cache in 4.481s 1:47:39 PM: Starting to extract cache 1:47:48 PM: Finished extracting cache in 8.55s 1:47:48 PM: Finished fetching cache in 13.122s 1:47:48 PM: Starting to prepare the repo for build 1:47:48 PM: Preparing Git Reference refs/heads/staging 1:47:50 PM: Starting to install dependencies 1:47:51 PM: Python version set to 3.8 1:47:51 PM: Attempting Ruby version 2.7.2, read from environment 1:47:51 PM: Using Ruby version 2.7.2 1:47:52 PM: Started restoring cached go cache 1:47:52 PM: Finished restoring cached go cache 1:47:53 PM: go version go1.19.13 linux/amd64 1:47:54 PM: Using PHP version 8.0 1:47:55 PM: Started restoring cached Node.js version 1:47:57 PM: Finished restoring cached Node.js version 1:47:57 PM: Attempting Node.js version '20' from .nvmrc 1:47:58 PM: v20.12.2 is already installed. 1:47:58 PM: Now using node v20.12.2 (npm v10.5.0) 1:47:58 PM: Enabling Node.js Corepack 1:47:58 PM: Started restoring cached build plugins 1:47:58 PM: Finished restoring cached build plugins 1:47:58 PM: Started restoring cached corepack dependencies 1:47:58 PM: Finished restoring cached corepack dependencies 1:47:58 PM: Started restoring cached pnpm cache 1:47:58 PM: Finished restoring cached pnpm cache 1:47:59 PM: Installing npm packages using pnpm version 8.14.1 1:47:59 PM: Lockfile is up to date, resolution step is skipped 1:48:00 PM: Progress: resolved 1, reused 0, downloaded 0, added 0 1:48:00 PM: Packages: +1094 1:48:00 PM: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1:48:01 PM: Progress: resolved 1094, reused 1090, downloaded 0, added 159 1:48:02 PM: Progress: resolved 1094, reused 1090, downloaded 1, added 1091 1:48:03 PM: Progress: resolved 1094, reused 1090, downloaded 3, added 1093 1:48:04 PM: Progress: resolved 1094, reused 1090, downloaded 4, added 1093 1:48:04 PM: Progress: resolved 1094, reused 1090, downloaded 4, added 1094, done 1:48:04 PM: dependencies: 1:48:04 PM: + @hyperobjekt/cms-config 3.0.0 1:48:04 PM: + @motionone/utils 10.17.0 1:48:04 PM: + @next/third-parties 14.1.4 1:48:04 PM: + @radix-ui/react-form 0.0.3 1:48:04 PM: + @radix-ui/react-icons 1.3.0 1:48:04 PM: + @radix-ui/react-navigation-menu 1.1.3 1:48:04 PM: + @radix-ui/react-slot 1.0.2 1:48:04 PM: + clsx 2.1.0 1:48:04 PM: + framer-motion 11.0.12 1:48:04 PM: + lodash 4.17.21 1:48:04 PM: + modern-normalize 2.0.0 1:48:04 PM: + netlify-cms-app 2.15.72 1:48:04 PM: + next 14.2.0 1:48:04 PM: + react 18.2.0 1:48:04 PM: + react-aria-components 1.1.1 1:48:04 PM: + react-dom 18.2.0 1:48:04 PM: + react-markdown 9.0.1 1:48:04 PM: + react-snap-carousel 0.4.0 1:48:04 PM: + sharp 0.32.5 1:48:04 PM: devDependencies: 1:48:04 PM: + @hyperobjekt/eslint-config 1.0.4 1:48:04 PM: + eslint 8.57.0 1:48:04 PM: + eslint-config-next 14.1.4 1:48:04 PM: + eslint-plugin-compat 4.1.4 1:48:04 PM: + husky 8.0.3 1:48:04 PM: + lint-staged 15.2.2 1:48:04 PM: + npm-run-all 4.1.5 1:48:04 PM: + prettier 3.0.2 1:48:04 PM: > @hyperobjekt/next-starter@1.0.0 prepare /opt/build/repo 1:48:04 PM: > husky install 1:48:04 PM: husky - Git hooks installed 1:48:04 PM: Done in 4.8s 1:48:04 PM: npm packages installed using pnpm 1:48:05 PM: Successfully installed dependencies 1:48:05 PM: Starting build script 1:48:06 PM: Detected 1 framework(s) 1:48:06 PM: "next" at version "14.2.0" 1:48:06 PM: Section completed: initializing 1:48:07 PM: ​ 1:48:07 PM: Netlify Build 1:48:07 PM: ──────────────────────────────────────────────────────────────── 1:48:07 PM: ​ 1:48:07 PM: ❯ Version 1:48:07 PM: @netlify/build 29.39.1 1:48:07 PM: ​ 1:48:07 PM: ❯ Flags 1:48:07 PM: baseRelDir: true 1:48:07 PM: buildId: 661eb9a8cc8e6e000834d237 1:48:07 PM: deployId: 661eb9a8cc8e6e000834d239 1:48:07 PM: ​ 1:48:07 PM: ❯ Current directory 1:48:07 PM: /opt/build/repo 1:48:07 PM: ​ 1:48:07 PM: ❯ Config file 1:48:07 PM: No config file was defined: using default values. 1:48:07 PM: ​ 1:48:07 PM: ❯ Context 1:48:07 PM: branch-deploy 1:48:07 PM: ​ 1:48:07 PM: ❯ Installing plugins 1:48:07 PM: - @netlify/plugin-nextjs@5.1.0 1:48:08 PM: ​ 1:48:08 PM: ❯ Using Next.js Runtime - v5.1.0 1:48:09 PM: ​ 1:48:09 PM: @netlify/plugin-nextjs (onPreBuild event) 1:48:09 PM: ──────────────────────────────────────────────────────────────── 1:48:09 PM: ​ 1:48:09 PM: No Next.js cache to restore 1:48:09 PM: ​ 1:48:09 PM: (@netlify/plugin-nextjs onPreBuild completed in 10ms) 1:48:09 PM: ​ 1:48:09 PM: Build command from Netlify app 1:48:09 PM: ──────────────────────────────────────────────────────────────── 1:48:09 PM: ​ 1:48:09 PM: $ pnpm run build 1:48:10 PM: > @hyperobjekt/next-starter@1.0.0 build /opt/build/repo 1:48:10 PM: > next build 1:48:10 PM: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache 1:48:10 PM: ▲ Next.js 14.2.0 1:48:10 PM: Creating an optimized production build ... 1:48:33 PM: ✓ Compiled successfully 1:48:33 PM: Linting and checking validity of types ... 1:48:33 PM: Browserslist: caniuse-lite is outdated. Please run: 1:48:33 PM: npx update-browserslist-db@latest 1:48:33 PM: Why you should do it regularly: https://github.com/browserslist/update-db#readme 1:48:33 PM: Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration . 1:48:37 PM: ./src/app/(site)/case-studies/[slug]/page.jsx 1:48:37 PM: 48:11 Warning: Using `` could result in slower LCP and higher bandwidth. Consider using `` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element @next/next/no-img-element 1:48:37 PM: info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules 1:48:37 PM: Collecting page data ... 1:48:39 PM: Generating static pages (0/9) ... 1:48:39 PM: Generating static pages (2/9) 1:48:39 PM: ⚠ metadataBase property in metadata export is not set for resolving social open graph or twitter images, using "http://localhost:3000". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase 1:48:39 PM: ⚠ metadataBase property in metadata export is not set for resolving social open graph or twitter images, using "http://localhost:3000". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase 1:48:39 PM: Generating static pages (4/9) 1:48:39 PM: /images/case-study-eviction-lab.png 1:48:39 PM: /images/case-study-eviction-lab.png 1:48:39 PM: ⚠ metadataBase property in metadata export is not set for resolving social open graph or twitter images, using "http://localhost:3000". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase 1:48:39 PM: ⚠ metadataBase property in metadata export is not set for resolving social open graph or twitter images, using "http://localhost:3000". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase 1:48:39 PM: Generating static pages (6/9) 1:48:41 PM: ✓ Generating static pages (9/9) 1:48:42 PM: Finalizing page optimization ... 1:48:42 PM: Collecting build traces ... 1:48:49 PM: Route (app) Size First Load JS 1:48:49 PM: ┌ ○ / 35.4 kB 147 kB 1:48:49 PM: ├ ○ /_not-found 876 B 88.3 kB 1:48:49 PM: ├ ○ /about 2.17 kB 106 kB 1:48:49 PM: ├ ○ /admin 511 B 87.9 kB 1:48:49 PM: ├ ● /case-studies/[slug] 2.01 kB 106 kB 1:48:49 PM: ├ └ /case-studies/eviction-lab 1:48:49 PM: └ ○ /our-work 64.4 kB 168 kB 1:48:49 PM: + First Load JS shared by all 87.4 kB 1:48:49 PM: ├ chunks/7fe4e03a-f789953c7e69f21c.js 53.6 kB 1:48:49 PM: ├ chunks/941-1e52467d93ae206b.js 31.6 kB 1:48:49 PM: └ other shared chunks (total) 2.13 kB 1:48:49 PM: ○ (Static) prerendered as static content 1:48:49 PM: ● (SSG) prerendered as static HTML (uses getStaticProps) 1:48:49 PM: ​ 1:48:49 PM: (build.command completed in 39.4s) 1:48:49 PM: ​ 1:48:49 PM: @netlify/plugin-nextjs (onBuild event) 1:48:49 PM: ──────────────────────────────────────────────────────────────── 1:48:49 PM: ​ 1:48:49 PM: ​ 1:48:49 PM: @netlify/plugin-nextjs (onEnd event) 1:48:49 PM: ──────────────────────────────────────────────────────────────── 1:48:49 PM: ​ 1:48:49 PM: ​ 1:48:49 PM: (@netlify/plugin-nextjs onEnd completed in 6ms) 1:48:49 PM: ​ 1:48:49 PM: Plugin "@netlify/plugin-nextjs" failed 1:48:49 PM: ──────────────────────────────────────────────────────────────── 1:48:49 PM: ​ 1:48:49 PM: Error message 1:48:49 PM: Error: Your publish directory does not contain expected Next.js build output, please check your build settings 1:48:49 PM: ​ 1:48:49 PM: Plugin details 1:48:49 PM: Package: @netlify/plugin-nextjs 1:48:49 PM: Version: 5.1.0 1:48:49 PM: Repository: git+https://github.com/netlify/next-runtime-minimal.git 1:48:49 PM: npm link: https://www.npmjs.com/package/@netlify/plugin-nextjs 1:48:49 PM: Report issues: https://github.com/netlify/next-runtime-minimal/issues 1:48:49 PM: ​ 1:48:49 PM: Error location 1:48:49 PM: In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app 1:48:49 PM: ​ 1:48:49 PM: Resolved config 1:48:49 PM: build: 1:48:49 PM: command: pnpm run build 1:48:49 PM: commandOrigin: ui 1:48:49 PM: environment: 1:48:49 PM: - NETLIFY_NEXT_PLUGIN_SKIP 1:48:49 PM: publish: /opt/build/repo/out 1:48:49 PM: publishOrigin: ui 1:48:49 PM: plugins: 1:48:49 PM: - inputs: {} 1:48:49 PM: origin: ui 1:48:49 PM: package: '@netlify/plugin-nextjs' 1:48:49 PM: Build failed due to a user error: Build script returned non-zero exit code: 2 1:48:50 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2) 1:48:50 PM: Failing build: Failed to build site 1:48:50 PM: Finished processing build request in 1m15.217s ```

Function logs

No response

.next JSON files

No response

ascorbic commented 5 months ago

Hi. Thanks for the report. It loioks like this is a bug related to the way we now handle export. In the new runtime we do handle sites that use output: "export", so it doesn't need to be disabled. However it does need the publish dir to be set to .next. We should be handling this gracefully though, so this will be fixed. In the meantime, manually setting it back to .next will mean it works again, and you will get the benefit of things like caching from the runtime.

joebentaylor1995 commented 5 months ago

The publish dir of .next is not an optimised build in comparison to the out folder. This needs to be out.

Hi. Thanks for the report. It loioks like this is a bug related to the way we now handle export. In the new runtime we do handle sites that use output: "export", so it doesn't need to be disabled. However it does need the publish dir to be set to .next. We should be handling this gracefully though, so this will be fixed. In the meantime, manually setting it back to .next will mean it works again, and you will get the benefit of things like caching from the runtime.

joebentaylor1995 commented 5 months ago

All my sites are currently broken due to this, is there no way to force netlify to use version 4 of runtime whilst this is fixed? @ascorbic

ascorbic commented 5 months ago

The runtime handles it - it doesn't publish the actual .next files, but it expects that to be the publish dir so that it can find the generated config. We should be handling it gracefully though, so this is just a workaround.

joebentaylor1995 commented 5 months ago

No worries, I've reverted back to V4 runtime for the time being.

For anybody seeing this, this how to do that:

  1. Create a netlify.toml file (if you havent already got one)
  2. Paste the following into this file:
    [[plugins]]
    package = "@netlify/plugin-nextjs"
  3. Install the dependancy @netlify/plugin-nextjs@4
cfhull commented 5 months ago

Hi. Thanks for the report. It loioks like this is a bug related to the way we now handle export. In the new runtime we do handle sites that use output: "export", so it doesn't need to be disabled. However it does need the publish dir to be set to .next. We should be handling this gracefully though, so this will be fixed. In the meantime, manually setting it back to .next will mean it works again, and you will get the benefit of things like caching from the runtime.

This worked for me. Thanks!

ascorbic commented 5 months ago

The fix for this is in version 5.1.2 of the runtime, which will roll out to users over the next day or can be installed manually if you want it now. With that you don't need to do anything with the publish dir, as we'll detect the correct location for where it is being built.