opennextjs / opennextjs-netlify

Open Next.js adapter for Netlify
https://opennext.js.org/netlify
676 stars 86 forks source link

[Bug]: Netlify CMS/ Next.JS starter template error: The directory "dist" does not contain a Next.js production build #1184

Closed vnn8248 closed 2 years ago

vnn8248 commented 2 years ago

Summary

Using the "one-click" Next.JS blog template with Netlify CMS, the build fails.

Following the steps to connect Github and deploy on Netlify are straightforward and just a couple of clicks. [https://www.netlifycms.org/docs/start-with-a-template/]

Error from deploy log in Netlify: ──────────────────────────────────────────────────────────────── 9:39:13 AM: Plugin "@netlify/plugin-nextjs" failed
9:39:13 AM: ──────────────────────────────────────────────────────────────── 9:39:13 AM: ​ 9:39:13 AM: Error message 9:39:13 AM: Error: The directory "dist" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory. 9:39:13 AM: In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config. 9:39:13 AM: If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true". 9:39:13 AM: ​ 9:39:13 AM: Plugin details 9:39:13 AM: Package: @netlify/plugin-nextjs 9:39:13 AM: Version: 4.2.1 9:39:13 AM: Repository: git+https://github.com/netlify/netlify-plugin-nextjs.git 9:39:13 AM: npm link: https://www.npmjs.com/package/@netlify/plugin-nextjs 9:39:13 AM: Report issues: https://github.com/netlify/netlify-plugin-nextjs/issues 9:39:13 AM: ​ 9:39:13 AM: Error location 9:39:13 AM: In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app 9:39:13 AM: at checkNextSiteHasBuilt (/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/verification.js:68:16) 9:39:13 AM: at onBuild (/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/index.js:37:50) 9:39:13 AM: ​

Steps to reproduce

Navigate here [https://www.netlifycms.org/docs/start-with-a-template/]

Click on the Next.js template Connect Github Observe Netlify deploy logs

A link to a reproduction repository

No response

Plugin version

4.2.1

More information about your build

What OS are you using?

Mac OS

Your netlify.toml file

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

Your public/_redirects file

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

Your next.config.js file

`next.config.js` ```toml # Paste content of your `next.config.js` file here. Check there is no private info in there. ```

Builds logs (or link to your logs)

Build logs ``` # Paste logs here ```

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. ```
jadamconnor commented 2 years ago

I get the same error but instead of with "dist" it specifies that my "public" folder is missing the next build. As a temporary workaround I've just removed the plugin from Netlify.

I have another Next project on Netlify using an older minor version (not sure where to find the minor versions) prompting me to update. But this project is building fine, so I'm not going to do that. Both projects are near carbon copies structurally and dependency-wise.

Any way to roll back the one project's plugin?

ascorbic commented 2 years ago

@vnn8248 It looks like the template needs updating. Because the site uses next export, you need to do as the message says and set NETLIFY_NEXT_PLUGIN_SKIP to true. You can set this in the Build > Enviornment section in the site UI.

ascorbic commented 2 years ago

@jadamconnor If your build command is next build, you should set the publish folder to .next. If you are using next export, follow the intruction about setting NETLIFY_NEXT_PLUGIN_SKIP

jadamconnor commented 2 years ago

@jadamconnor If your build command is next build, you should set the publish folder to .next. If you are using next export, follow the intruction about setting NETLIFY_NEXT_PLUGIN_SKIP

I am using next build and I have not changed its default from .next.

ascorbic commented 2 years ago

Could you open another issue, as I think it's different. Please can you include the details requested in the tempkate, particularly the build logs. Thanks.

accexs commented 2 years ago

am also having this problem, am trying the nextjs template here -> https://www.netlifycms.org/docs/start-with-a-template/

already tried with NETLIFY_NEXT_PLUGIN_SKIP to true and no luck.


4:52:20 AM: Build ready to start
4:52:22 AM: build-image version: 122b31996ccaffd45d820a452d6227f8312110cc (focal)
4:52:22 AM: build-image tag: v4.5.3
4:52:22 AM: buildbot version: 9916c4a6a180865eb3ec6a342637fd13b29e1096
4:52:22 AM: Fetching cached dependencies
4:52:22 AM: Failed to fetch cache, continuing with build
4:52:22 AM: Starting to prepare the repo for build
4:52:22 AM: No cached dependencies found. Cloning fresh repo
4:52:22 AM: git clone https://github.com/wutali/nextjs-netlify-blog-template
4:52:23 AM: Preparing Git Reference refs/heads/master
4:52:23 AM: Parsing package.json dependencies
4:52:25 AM: Starting build script
4:52:25 AM: Installing dependencies
4:52:25 AM: Python version set to 2.7
4:52:25 AM: Downloading and installing node v16.14.0...
4:52:26 AM: Downloading https://nodejs.org/dist/v16.14.0/node-v16.14.0-linux-x64.tar.xz...
4:52:26 AM: Computing checksum with sha256sum
4:52:26 AM: Checksums matched!
4:52:30 AM: Now using node v16.14.0 (npm v8.3.1)
4:52:30 AM: Started restoring cached build plugins
4:52:30 AM: Finished restoring cached build plugins
4:52:30 AM: Attempting ruby version 2.7.2, read from environment
4:52:31 AM: Using ruby version 2.7.2
4:52:32 AM: Using PHP version 8.0
4:52:32 AM: Started restoring cached yarn cache
4:52:32 AM: Finished restoring cached yarn cache
4:52:32 AM: No yarn workspaces detected
4:52:32 AM: Started restoring cached node modules
4:52:32 AM: Finished restoring cached node modules
4:52:33 AM: Installing NPM modules using Yarn version 1.22.10
4:52:33 AM: yarn install v1.22.10
4:52:33 AM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
4:52:33 AM: [1/4] Resolving packages...
4:52:34 AM: [2/4] Fetching packages...
4:52:52 AM: info fsevents@2.3.2: The platform "linux" is incompatible with this module.
4:52:52 AM: info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
4:52:52 AM: [3/4] Linking dependencies...
4:52:52 AM: warning " > next-mdx-remote@2.1.3" has incorrect peer dependency "react@>=16.13.1 <=17.0.1".
4:52:52 AM: warning " > next-mdx-remote@2.1.3" has incorrect peer dependency "react-dom@>=16.13.1 <=17.0.1".
4:52:52 AM: warning " > react-instagram-embed@2.0.0" has incorrect peer dependency "react@^16.0.0 || ^15.0.0 || ~0.14.0".
4:52:52 AM: warning " > react-instagram-embed@2.0.0" has incorrect peer dependency "react-dom@^16.0.0 || ^15.0.0 || ~0.14.0".
4:52:52 AM: warning " > react-twitter-embed@3.0.3" has unmet peer dependency "prop-types@^15.5.4".
4:52:52 AM: warning " > react-twitter-embed@3.0.3" has incorrect peer dependency "react@^15.0.0 || ^16.0.0".
4:52:52 AM: warning " > react-twitter-embed@3.0.3" has incorrect peer dependency "react-dom@^15.0.0 || ^16.0.0".
4:52:52 AM: warning "react-twitter-embed > enzyme-adapter-react-16@1.15.6" has unmet peer dependency "enzyme@^3.0.0".
4:52:52 AM: warning "react-twitter-embed > enzyme-adapter-react-16@1.15.6" has incorrect peer dependency "react@^16.0.0-0".
4:52:52 AM: warning "react-twitter-embed > enzyme-adapter-react-16@1.15.6" has incorrect peer dependency "react-dom@^16.0.0-0".
4:52:52 AM: warning "react-twitter-embed > enzyme-adapter-react-16 > enzyme-adapter-utils@1.14.0" has incorrect peer dependency "react@0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0".
4:52:52 AM: warning "react-twitter-embed > enzyme-adapter-react-16 > react-test-renderer@16.14.0" has incorrect peer dependency "react@^16.14.0".
4:52:52 AM: warning "react-twitter-embed > enzyme-adapter-react-16 > enzyme-adapter-utils > airbnb-prop-types@2.16.0" has incorrect peer dependency "react@^0.14 || ^15.0.0 || ^16.0.0-alpha".
4:53:00 AM: [4/4] Building fresh packages...
4:53:00 AM: success Saved lockfile.
4:53:00 AM: Done in 26.60s.
4:53:00 AM: NPM modules installed using Yarn
4:53:00 AM: Started restoring cached go cache
4:53:00 AM: Finished restoring cached go cache
4:53:00 AM: go version go1.16.5 linux/amd64
4:53:00 AM: go version go1.16.5 linux/amd64
4:53:00 AM: Installing missing commands
4:53:00 AM: Verify run directory
4:53:02 AM: ​
4:53:02 AM: ────────────────────────────────────────────────────────────────
4:53:02 AM:   Netlify Build                                                 
4:53:02 AM: ────────────────────────────────────────────────────────────────
4:53:02 AM: ​
4:53:02 AM: ❯ Version
4:53:02 AM:   @netlify/build 26.2.7
4:53:02 AM: ​
4:53:02 AM: ❯ Flags
4:53:02 AM:   baseRelDir: true
4:53:02 AM:   buildId: 620615b433111d611118dd69
4:53:02 AM:   deployId: 620615b433111d611118dd6b
4:53:02 AM: ​
4:53:02 AM: ❯ Current directory
4:53:02 AM:   /opt/build/repo
4:53:02 AM: ​
4:53:02 AM: ❯ Config file
4:53:02 AM:   /opt/build/repo/netlify.toml
4:53:02 AM: ​
4:53:02 AM: ❯ Context
4:53:02 AM:   production
4:53:03 AM: ​
4:53:03 AM: ❯ Installing plugins
4:53:03 AM:    - @netlify/plugin-nextjs@4.2.5
4:53:18 AM: ​
4:53:18 AM: ❯ Loading plugins
4:53:18 AM:    - @netlify/plugin-nextjs@4.2.5 from Netlify app
4:53:20 AM: ​
4:53:20 AM: ────────────────────────────────────────────────────────────────
4:53:20 AM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
4:53:20 AM: ────────────────────────────────────────────────────────────────
4:53:20 AM: ​
4:53:20 AM: No Next.js cache to restore.
4:53:20 AM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
4:53:20 AM: ​
4:53:20 AM: (@netlify/plugin-nextjs onPreBuild completed in 46ms)
4:53:20 AM: ​
4:53:20 AM: ────────────────────────────────────────────────────────────────
4:53:20 AM:   2. build.command from netlify.toml                            
4:53:20 AM: ────────────────────────────────────────────────────────────────
4:53:20 AM: ​
4:53:20 AM: $ npm run export
4:53:21 AM: > my-app@0.1.1 export
4:53:21 AM: > next build && next export -o ./dist
4:53:21 AM: Browserslist: caniuse-lite is outdated. Please run:
4:53:21 AM: npx browserslist@latest --update-db
4:53:21 AM: Why you should do it regularly:
4:53:21 AM: https://github.com/browserslist/browserslist#browsers-data-updating
4:53:22 AM: (node:1710) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /opt/build/repo/node_modules/next/node_modules/postcss/package.json.
4:53:22 AM: Update this package.json to use a subpath pattern like "./*".
4:53:22 AM: (Use `node --trace-deprecation ...` to show where the warning was created)
4:53:22 AM: info  - Using webpack 4. Reason: future.webpack5 option not enabled https://nextjs.org/docs/messages/webpack5
4:53:23 AM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
4:53:23 AM: info  - Checking validity of types...
4:53:29 AM: info  - Creating an optimized production build...
4:53:29 AM: Browserslist: caniuse-lite is outdated. Please run:
4:53:29 AM: npx browserslist@latest --update-db
4:53:29 AM: Why you should do it regularly:
4:53:29 AM: https://github.com/browserslist/browserslist#browsers-data-updating
4:53:37 AM: Browserslist: caniuse-lite is outdated. Please run:
4:53:37 AM: npx browserslist@latest --update-db
4:53:37 AM: Why you should do it regularly:
4:53:37 AM: https://github.com/browserslist/browserslist#browsers-data-updating
4:53:48 AM: info  - Compiled successfully
4:53:48 AM: info  - Collecting page data...
4:53:50 AM: info  - Generating static pages (0/17)
4:53:52 AM: info  - Generating static pages (4/17)
4:53:52 AM: info  - Generating static pages (8/17)
4:53:55 AM: Browserslist: caniuse-lite is outdated. Please run:
4:53:55 AM: npx browserslist@latest --update-db
4:53:55 AM: Why you should do it regularly:
4:53:55 AM: https://github.com/browserslist/browserslist#browsers-data-updating
4:53:55 AM: Browserslist: caniuse-lite is outdated. Please run:
4:53:55 AM: npx browserslist@latest --update-db
4:53:55 AM: Why you should do it regularly:
4:53:55 AM: https://github.com/browserslist/browserslist#browsers-data-updating
4:53:55 AM: Browserslist: caniuse-lite is outdated. Please run:
4:53:55 AM: npx browserslist@latest --update-db
4:53:55 AM: Why you should do it regularly:
4:53:55 AM: https://github.com/browserslist/browserslist#browsers-data-updating
4:53:55 AM: Browserslist: caniuse-lite is outdated. Please run:
4:53:55 AM: npx browserslist@latest --update-db
4:53:55 AM: Why you should do it regularly:
4:53:55 AM: https://github.com/browserslist/browserslist#browsers-data-updating
4:53:55 AM: Browserslist: caniuse-lite is outdated. Please run:
4:53:55 AM: npx browserslist@latest --update-db
4:53:55 AM: Why you should do it regularly:
4:53:55 AM: https://github.com/browserslist/browserslist#browsers-data-updating
4:53:55 AM: Browserslist: caniuse-lite is outdated. Please run:
4:53:55 AM: npx browserslist@latest --update-db
4:53:55 AM: Why you should do it regularly:
4:53:55 AM: https://github.com/browserslist/browserslist#browsers-data-updating
4:53:56 AM: info  - Generating static pages (12/17)
4:53:57 AM: info  - Generating static pages (17/17)
4:53:57 AM: info  - Finalizing page optimization...
4:53:57 AM: Page                                Size     First Load JS
4:53:57 AM: ┌ ○ /                               2.54 kB        74.6 kB
4:53:57 AM: ├   /_app                           0 B            63.8 kB
4:53:57 AM: ├ ○ /404                            2.77 kB        66.6 kB
4:53:57 AM: ├ ● /posts                          1.35 kB        80.9 kB
4:53:57 AM: ├ ● /posts/[post]                   16.6 kB        96.1 kB
4:53:57 AM: ├   └ css/d9f998f12db559bf9cc0.css  631 B
4:53:57 AM: ├   ├ /posts/welcome
4:53:57 AM: ├   ├ /posts/markdown-syntax
4:53:57 AM: ├   ├ /posts/rich-content-with-mdx
4:53:57 AM: ├   └ [+3 more paths]
4:53:57 AM: ├ ● /posts/page/[page]              1.36 kB        80.9 kB
4:53:57 AM: ├   └ /posts/page/2
4:53:57 AM: └ ● /posts/tags/[[...slug]]         1.32 kB        80.8 kB
4:53:57 AM:     ├ /posts/tags/document
4:53:57 AM:     ├ /posts/tags/mock
4:53:57 AM:     ├ /posts/tags/style
4:53:57 AM:     └ [+3 more paths]
4:53:57 AM: + First Load JS shared by all       63.8 kB
4:53:57 AM:   ├ chunks/commons.5bc016.js        13.6 kB
4:53:57 AM:   ├ chunks/framework.2d0daf.js      42.1 kB
4:53:57 AM:   ├ chunks/main.0de564.js           6.8 kB
4:53:57 AM:   ├ chunks/pages/_app.5168e8.js     581 B
4:53:57 AM:   ├ chunks/webpack.50bee0.js        751 B
4:53:57 AM:   └ css/7e37b93ade22ad15b8af.css    1.01 kB
4:53:57 AM: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
4:53:57 AM: ○  (Static)  automatically rendered as static HTML (uses no initial props)
4:53:57 AM: ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
4:53:57 AM:    (ISR)     incremental static regeneration (uses revalidate in getStaticProps)
4:53:58 AM: info  - Using webpack 4. Reason: future.webpack5 option not enabled https://nextjs.org/docs/messages/webpack5
4:53:58 AM: info  - using build directory: /opt/build/repo/.next
4:53:58 AM: info  - Copying "static build" directory
4:53:58 AM: info  - No "exportPathMap" found in "next.config.js". Generating map from "./pages"
4:53:58 AM: info  - Launching 7 workers
4:53:58 AM: info  - Exporting (0/3)
4:53:58 AM: info  - Copying "public" directory
4:53:59 AM: info  - Exporting (3/3)
4:53:59 AM: Export successful. Files written to /opt/build/repo/dist
4:53:59 AM: ​
4:53:59 AM: (build.command completed in 39s)
4:53:59 AM: ​
4:53:59 AM: ────────────────────────────────────────────────────────────────
4:53:59 AM:   3. @netlify/plugin-nextjs (onBuild event)                     
4:53:59 AM: ────────────────────────────────────────────────────────────────
4:53:59 AM: ​
4:53:59 AM: ​
4:53:59 AM: ────────────────────────────────────────────────────────────────
4:53:59 AM:   Plugin "@netlify/plugin-nextjs" failed                        
4:53:59 AM: ────────────────────────────────────────────────────────────────
4:53:59 AM: ​
4:53:59 AM:   Error message
4:53:59 AM:   Error: The directory "dist" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
4:53:59 AM:   In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.
4:53:59 AM:   If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
4:53:59 AM: ​
4:53:59 AM:   Plugin details
4:53:59 AM:   Package:        @netlify/plugin-nextjs
4:53:59 AM:   Version:        4.2.5
4:53:59 AM:   Repository:     git+https://github.com/netlify/netlify-plugin-nextjs.git
4:53:59 AM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
4:53:59 AM:   Report issues:  https://github.com/netlify/netlify-plugin-nextjs/issues
4:53:59 AM: ​
4:53:59 AM:   Error location
4:53:59 AM:   In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app
4:53:59 AM:       at checkNextSiteHasBuilt (/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/verification.js:68:16)
4:53:59 AM:       at onBuild (/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/index.js:37:50)
4:53:59 AM: ​
4:53:59 AM:   Resolved config
4:53:59 AM:   build:
4:53:59 AM:     command: npm run export
4:53:59 AM:     commandOrigin: config
4:53:59 AM:     environment:
4:53:59 AM:       - NEXT_PRIVATE_TARGET
4:53:59 AM:     publish: /opt/build/repo/dist
4:53:59 AM:     publishOrigin: config
4:53:59 AM:   plugins:
4:53:59 AM:     - inputs: {}
4:53:59 AM:       origin: ui
4:53:59 AM:       package: '@netlify/plugin-nextjs'
4:54:00 AM: Caching artifacts
4:54:00 AM: Started saving node modules
4:54:00 AM: Finished saving node modules
4:54:00 AM: Started saving build plugins
4:54:00 AM: Finished saving build plugins
4:54:00 AM: Started saving yarn cache
4:54:04 AM: Finished saving yarn cache
4:54:04 AM: Started saving pip cache
4:54:04 AM: Finished saving pip cache
4:54:04 AM: Started saving emacs cask dependencies
4:54:04 AM: Finished saving emacs cask dependencies
4:54:04 AM: Started saving maven dependencies
4:54:04 AM: Finished saving maven dependencies
4:54:04 AM: Started saving boot dependencies
4:54:04 AM: Finished saving boot dependencies
4:54:04 AM: Started saving rust rustup cache
4:54:04 AM: Finished saving rust rustup cache
4:54:04 AM: Started saving go dependencies
4:54:04 AM: Finished saving go dependencies
4:54:07 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:54:07 AM: Creating deploy upload records
4:54:07 AM: Failing build: Failed to build site
4:54:07 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2
4:54:07 AM: Finished processing build request in 1m45.215100515s
ascorbic commented 2 years ago

Hi @accexs Can you let me know where you are setting NETLIFY_NEXT_PLUGIN_SKIP? It doesn't seem to be being found.

nivvyart commented 2 years ago

This worked for me after updating the build env variable

Here are more details on setting this build variable: https://docs.netlify.com/configure-builds/common-configurations/#next-js

For apps that use next export to generate static HTML, set the NETLIFY_NEXT_PLUGIN_SKIP environment variable to true.

hkennyv commented 2 years ago

FYI for anyone else having this problem. I just resolved this on my repo using the following:

[[plugins]]
package = "@netlify/plugin-nextjs"

[build]
publish = ".next"
Build command: yarn build
Publish directory: .next

What I had before (was working until today):

[build]
    command = "yarn build && yarn export"
    publish = "out"

Build settings:

Build command: yarn build && yarn export
Publish directory: out
ascorbic commented 2 years ago

Closing this as it should be fixed by setting NETLIFY_NEXT_PLUGIN_SKIP. If this doesn't solve it, please open a new issue

amalikmuhd commented 1 year ago

Hi, I am trying to deploy nextjs app on netlify. it keeps failing below is the error I got.

Screenshot 2022-12-03 at 04 49 24 Screenshot 2022-12-03 at 04 49 34
ascorbic commented 1 year ago

@codewithmalik That's a Next.js error about a problem with your site, rather than a problem speicifically with building on Netlify. There's a problem with your site in your es1.js page.