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
638 stars 85 forks source link

[Bug]: Plugin "@netlify/plugin-nextjs" failed #1185

Closed jadamconnor closed 2 years ago

jadamconnor commented 2 years ago

Summary

My Nextjs build is failing with the following error:

Plugin "@netlify/plugin-nextjs" failed

Error: The directory "public" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.
If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".

In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app and package.json at checkNextSiteHasBuilt (/node_modules/@netlify/plugin-nextjs/lib/helpers/verification.js:68:16) at onBuild (/node_modules/@netlify/plugin-nextjs/lib/index.js:37:50)

I'm using Next build, not Next export and the default publish directory (.next) has not been altered. It looks like the plugin is looking for the build in build.

Steps to reproduce

Deploy build to Netlify.

A link to a reproduction repository

No response

Plugin version

4.2.2

More information about your build

What OS are you using?

Mac OS

Your netlify.toml file

No response

Your public/_redirects file

`_redirects` ```toml # Paste content of your `_redirects` file here ```

Your next.config.js file

`next.config.js` ```toml module.exports = { reactStrictMode: true, images: { domains: ['localhost', 'xxxxx.wpengine.com'], } } ```

Builds logs (or link to your logs)

Build logs ``` 10:21:18 AM: Build ready to start 10:21:21 AM: build-image version: 122b31996ccaffd45d820a452d6227f8312110cc (focal) 10:21:21 AM: build-image tag: v4.5.3 10:21:21 AM: buildbot version: b9fe2d4aead91245e5ab227e25498d66c4f1ea02 10:21:22 AM: Fetching cached dependencies 10:21:22 AM: Starting to download cache of 218.3MB 10:21:25 AM: Finished downloading cache in 3.062379086s 10:21:25 AM: Starting to extract cache 10:21:35 AM: Finished extracting cache in 10.16937025s 10:21:35 AM: Finished fetching cache in 13.271576219s 10:21:35 AM: Starting to prepare the repo for build 10:21:35 AM: Preparing Git Reference refs/heads/main 10:21:36 AM: Parsing package.json dependencies 10:21:37 AM: Starting build script 10:21:37 AM: Installing dependencies 10:21:37 AM: Python version set to 2.7 10:21:37 AM: Started restoring cached node version 10:21:39 AM: Finished restoring cached node version 10:21:39 AM: v16.13.2 is already installed. 10:21:40 AM: Now using node v16.13.2 (npm v8.1.2) 10:21:40 AM: Started restoring cached build plugins 10:21:40 AM: Finished restoring cached build plugins 10:21:40 AM: Attempting ruby version 2.7.2, read from environment 10:21:42 AM: Using ruby version 2.7.2 10:21:42 AM: Using PHP version 8.0 10:21:42 AM: Started restoring cached node modules 10:21:42 AM: Finished restoring cached node modules 10:21:42 AM: Started restoring cached go cache 10:21:42 AM: Finished restoring cached go cache 10:21:42 AM: go version go1.16.5 linux/amd64 10:21:42 AM: go version go1.16.5 linux/amd64 10:21:42 AM: Installing missing commands 10:21:42 AM: Verify run directory 10:21:44 AM: ​ 10:21:44 AM: ──────────────────────────────────────────────────────────────── 10:21:44 AM: Netlify Build 10:21:44 AM: ──────────────────────────────────────────────────────────────── 10:21:44 AM: ​ 10:21:44 AM: ❯ Version 10:21:44 AM: @netlify/build 26.2.2 10:21:44 AM: ​ 10:21:44 AM: ❯ Flags 10:21:44 AM: baseRelDir: true 10:21:44 AM: buildId: 61f80c7e745620000795afe9 10:21:44 AM: deployId: 61f80c7e745620000795afeb 10:21:44 AM: ​ 10:21:44 AM: ❯ Current directory 10:21:44 AM: /opt/build/repo 10:21:44 AM: ​ 10:21:44 AM: ❯ Config file 10:21:44 AM: No config file was defined: using default values. 10:21:44 AM: ​ 10:21:44 AM: ❯ Context 10:21:44 AM: production 10:21:44 AM: ​ 10:21:44 AM: ❯ Loading plugins 10:21:44 AM: - @netlify/plugin-nextjs@4.2.2 from Netlify app and package.json 10:21:46 AM: ​ 10:21:46 AM: ──────────────────────────────────────────────────────────────── 10:21:46 AM: 1. @netlify/plugin-nextjs (onPreBuild event) 10:21:46 AM: ──────────────────────────────────────────────────────────────── 10:21:46 AM: ​ 10:21:46 AM: No Next.js cache to restore. 10:21:46 AM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed. 10:21:46 AM: ​ 10:21:46 AM: (@netlify/plugin-nextjs onPreBuild completed in 39ms) 10:21:46 AM: ​ 10:21:46 AM: ──────────────────────────────────────────────────────────────── 10:21:46 AM: 2. Build command from Netlify app 10:21:46 AM: ──────────────────────────────────────────────────────────────── 10:21:46 AM: ​ 10:21:46 AM: $ npm run build 10:21:46 AM: > build 10:21:46 AM: > next build 10:21:47 AM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache 10:21:47 AM: info - Checking validity of types... 10:21:51 AM: ./pages/careers.js 10:21:51 AM: 35:8 Warning: React Hook useEffect has a missing dependency: 'jobOpenings'. Either include it or remove the dependency array. If 'setOpenings' needs the current value of 'jobOpenings', you can also switch to useReducer instead of useState and read 'jobOpenings' in the reducer. react-hooks/exhaustive-deps 10:21:51 AM: ./pages/justicepoint-careers.js 10:21:51 AM: 33:8 Warning: React Hook useEffect has a missing dependency: 'jobOpenings'. Either include it or remove the dependency array. If 'setOpenings' needs the current value of 'jobOpenings', you can also switch to useReducer instead of useState and read 'jobOpenings' in the reducer. react-hooks/exhaustive-deps 10:21:51 AM: ./pages/news.js 10:21:51 AM: 37:8 Warning: React Hook useEffect has a missing dependency: 'newsItems'. Either include it or remove the dependency array. If 'setFilteredNews' needs the current value of 'newsItems', you can also switch to useReducer instead of useState and read 'newsItems' in the reducer. react-hooks/exhaustive-deps 10:21:51 AM: ./pages/programs.js 10:21:51 AM: 35:8 Warning: React Hook useEffect has a missing dependency: 'programs'. Either include it or remove the dependency array. react-hooks/exhaustive-deps 10:21:51 AM: ./components/header.js 10:21:51 AM: 17:11 Warning: The 'handleScroll' function makes the dependencies of useEffect Hook (at line 32) change on every render. Move it inside the useEffect callback. Alternatively, wrap the definition of 'handleScroll' in its own useCallback() Hook. react-hooks/exhaustive-deps 10:21:51 AM: 88:29 Warning: passHref is missing. See: https://nextjs.org/docs/messages/link-passhref @next/next/link-passhref 10:21:51 AM: info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules 10:21:51 AM: info - Creating an optimized production build... 10:22:33 AM: info - Compiled successfully 10:22:33 AM: info - Collecting page data... 10:22:39 AM: info - Generating static pages (0/38) 10:22:43 AM: Invalid href passed to next/router: /news//recovery-reimagined, repeated forward-slashes (//) or backslashes \ are not valid in the href 10:22:45 AM: info - Generating static pages (9/38) 10:22:49 AM: info - Generating static pages (18/38) 10:22:53 AM: info - Generating static pages (28/38) 10:22:54 AM: info - Generating static pages (38/38) 10:22:54 AM: info - Finalizing page optimization... 10:22:54 AM: Page Size First Load JS 10:22:54 AM: ┌ ● / (ISR: 60 Seconds) (4611 ms) 2.14 kB 126 kB 10:22:54 AM: ├ /_app 0 B 79.2 kB 10:22:54 AM: ├ ○ /404 196 B 79.4 kB 10:22:54 AM: ├ ● /about (ISR: 60 Seconds) (3737 ms) 1.89 kB 126 kB 10:22:54 AM: ├ λ /api/hello 0 B 79.2 kB 10:22:54 AM: ├ ● /apply/[slug] (ISR: 1 Seconds) (5868 ms) 5.21 kB 101 kB 10:22:54 AM: ├ ├ /apply/mental-health-substance-abuse-professional (3201 ms) 10:22:54 AM: ├ └ /apply/cope-line-assistant (2667 ms) 10:22:54 AM: ├ ● /careers (ISR: 60 Seconds) (5448 ms) 4.47 kB 94.3 kB 10:22:54 AM: ├ ● /careers/[slug] (ISR: 60 Seconds) (10601 ms) 2.47 kB 91.9 kB 10:22:54 AM: ├ ├ /careers/mental-health-substance-abuse-professional (1942 ms) 10:22:54 AM: ├ ├ /careers/cope-line-assistant (1835 ms) 10:22:54 AM: ├ ├ /careers/jail-screening-specialist-4 (1805 ms) 10:22:54 AM: ├ ├ /careers/case-manager (1802 ms) 10:22:54 AM: ├ ├ /careers/diversion-case-manager-2 (1642 ms) 10:22:54 AM: ├ └ /careers/jp-installer (1575 ms) 10:22:54 AM: ├ ● /contact (ISR: 60 Seconds) (2014 ms) 56.7 kB 146 kB 10:22:54 AM: ├ ● /jp-apply/[slug] (ISR: 1 Seconds) (10777 ms) 3.73 kB 89.6 kB 10:22:54 AM: ├ ├ /jp-apply/jp-installer (2921 ms) 10:22:54 AM: ├ ├ /jp-apply/diversion-case-manager-2 (2670 ms) 10:22:54 AM: ├ ├ /jp-apply/case-manager (2641 ms) 10:22:54 AM: ├ └ /jp-apply/jail-screening-specialist-4 (2545 ms) 10:22:54 AM: ├ ● /justicepoint-careers (ISR: 60 Seconds) (3514 ms) 3.05 kB 87.4 kB 10:22:54 AM: ├ ● /justicepoint-careers/[slug] (ISR: 60 Seconds) (15129 ms) 2.86 kB 82 kB 10:22:54 AM: ├ ├ /justicepoint-careers/mental-health-substance-abuse-professional (2684 ms) 10:22:54 AM: ├ ├ /justicepoint-careers/case-manager (2667 ms) 10:22:54 AM: ├ ├ /justicepoint-careers/cope-line-assistant (2620 ms) 10:22:54 AM: ├ ├ /justicepoint-careers/jail-screening-specialist-4 (2488 ms) 10:22:54 AM: ├ ├ /justicepoint-careers/diversion-case-manager-2 (2452 ms) 10:22:54 AM: ├ └ /justicepoint-careers/jp-installer (2218 ms) 10:22:54 AM: ├ ● /news (ISR: 60 Seconds) (3857 ms) 3.79 kB 93.6 kB 10:22:54 AM: ├ ● /programs (ISR: 60 Seconds) (4138 ms) 3.96 kB 93.8 kB 10:22:54 AM: ├ ● /programs/ap (ISR: 60 Seconds) (2712 ms) 1.28 kB 126 kB 10:22:54 AM: ├ ● /programs/ccs (ISR: 60 Seconds) (4257 ms) 822 B 93 kB 10:22:54 AM: ├ ● /programs/chcm (ISR: 60 Seconds) (3640 ms) 803 B 93 kB 10:22:54 AM: ├ ● /programs/cope-line (ISR: 60 Seconds) (2632 ms) 1.23 kB 126 kB 10:22:54 AM: ├ ● /programs/hph (ISR: 60 Seconds) (2294 ms) 1.23 kB 126 kB 10:22:54 AM: ├ ● /programs/otc (ISR: 60 Seconds) (3378 ms) 32.5 kB 157 kB 10:22:54 AM: ├ ● /programs/rsc (ISR: 60 Seconds) (3632 ms) 567 B 92.8 kB 10:22:54 AM: ├ ● /programs/sa (ISR: 60 Seconds) (3744 ms) 566 B 92.8 kB 10:22:54 AM: ├ ● /programs/tad (ISR: 60 Seconds) (2617 ms) 567 B 92.8 kB 10:22:54 AM: ├ ● /programs/teen (ISR: 60 Seconds) (3037 ms) 567 B 92.8 kB 10:22:54 AM: └ ● /programs/uh (ISR: 60 Seconds) (3083 ms) 568 B 92.8 kB 10:22:54 AM: + First Load JS shared by all 79.2 kB 10:22:54 AM: ├ chunks/framework-dc33c0b5493501f0.js 42 kB 10:22:54 AM: ├ chunks/main-96a77a0c69c34fa7.js 27 kB 10:22:54 AM: ├ chunks/pages/_app-3c35abdfef7e76b0.js 9.18 kB 10:22:54 AM: ├ chunks/webpack-09da375726426e9c.js 987 B 10:22:54 AM: └ css/0b790405d1f2d3e6.css 22 kB 10:22:54 AM: λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps) 10:22:54 AM: ○ (Static) automatically rendered as static HTML (uses no initial props) 10:22:54 AM: ● (SSG) automatically generated as static HTML + JSON (uses getStaticProps) 10:22:54 AM: (ISR) incremental static regeneration (uses revalidate in getStaticProps) 10:22:55 AM: ​ 10:22:55 AM: (build.command completed in 1m 8.6s) 10:22:55 AM: ​ 10:22:55 AM: ──────────────────────────────────────────────────────────────── 10:22:55 AM: 3. @netlify/plugin-nextjs (onBuild event) 10:22:55 AM: ──────────────────────────────────────────────────────────────── 10:22:55 AM: ​ 10:22:55 AM: ​ 10:22:55 AM: ──────────────────────────────────────────────────────────────── 10:22:55 AM: Plugin "@netlify/plugin-nextjs" failed 10:22:55 AM: ──────────────────────────────────────────────────────────────── 10:22:55 AM: ​ 10:22:55 AM: Error message 10:22:55 AM: Error: The directory "public" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory. 10:22:55 AM: In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config. 10:22:55 AM: If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true". 10:22:55 AM: ​ 10:22:55 AM: Plugin details 10:22:55 AM: Package: @netlify/plugin-nextjs 10:22:55 AM: Version: 4.2.2 10:22:55 AM: Repository: git+https://github.com/netlify/netlify-plugin-nextjs.git 10:22:55 AM: npm link: https://www.npmjs.com/package/@netlify/plugin-nextjs 10:22:55 AM: Report issues: https://github.com/netlify/netlify-plugin-nextjs/issues 10:22:55 AM: ​ 10:22:55 AM: Error location 10:22:55 AM: In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app and package.json 10:22:55 AM: at checkNextSiteHasBuilt (/node_modules/@netlify/plugin-nextjs/lib/helpers/verification.js:68:16) 10:22:55 AM: at onBuild (/node_modules/@netlify/plugin-nextjs/lib/index.js:37:50) 10:22:55 AM: ​ 10:22:55 AM: Resolved config 10:22:55 AM: build: 10:22:55 AM: command: npm run build 10:22:55 AM: commandOrigin: ui 10:22:55 AM: environment: 10:22:55 AM: - FONTAWESOME_NPM_AUTH_TOKEN 10:22:55 AM: - GATSBY_GA_MEASUREMENT_ID 10:22:55 AM: - GATSBY_WPGRAPHQL_URL 10:22:55 AM: - NEXT_PUBLIC_WORDPRESS_API_URL 10:22:55 AM: - NPM_TOKEN 10:22:55 AM: - NEXT_PRIVATE_TARGET 10:22:55 AM: publish: /opt/build/repo/public 10:22:55 AM: publishOrigin: ui 10:22:55 AM: plugins: 10:22:55 AM: - inputs: {} 10:22:55 AM: origin: ui 10:22:55 AM: package: '@netlify/plugin-nextjs' 10:22:55 AM: Caching artifacts 10:22:55 AM: Started saving node modules 10:22:55 AM: Finished saving node modules 10:22:55 AM: Started saving build plugins 10:22:55 AM: Finished saving build plugins 10:22:55 AM: Started saving pip cache 10:22:55 AM: Finished saving pip cache 10:22:55 AM: Started saving emacs cask dependencies 10:22:55 AM: Finished saving emacs cask dependencies 10:22:55 AM: Started saving maven dependencies 10:22:55 AM: Finished saving maven dependencies 10:22:55 AM: Started saving boot dependencies 10:22:55 AM: Finished saving boot dependencies 10:22:55 AM: Started saving rust rustup cache 10:22:55 AM: Finished saving rust rustup cache 10:22:55 AM: Started saving go dependencies 10:22:55 AM: Finished saving go dependencies 10:22:55 AM: Build failed due to a user error: Build script returned non-zero exit code: 2 10:22:55 AM: Creating deploy upload records 10:22:55 AM: Failing build: Failed to build site 10:22:55 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 10:22:56 AM: Finished processing build request in 1m34.066860909s ```

Function logs

Function logs ``` # Paste logs here ```

.next JSON files

generated .next JSON files ``` # Paste file contents here. Please check there isn't any private info in them # You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time. ```
ascorbic commented 2 years ago

Hi @jadamconnor From that it seems like your publish directory is set to "public", when it should be ".next". You can either set it in the UI or in netlify.toml.

jadamconnor commented 2 years ago

Yep! Wow. I didn't think to check there because this setting is usually set to .next by default. Thank you. So sorry for the false report.

ascorbic commented 2 years ago

No worries. Glad it was fixed.