我无法将Next.js部署到netflix.由于@netlify/plugin-nextjs插件中的错误,部署失败.&l



我正在尝试部署我的nextjs应用netlify,但它一直扔我失败的错误,不部署这里是我的github repo https://github.com/farishelmipermana/nextjs-portfolio.git,我正试图通过改变yarn build && next export来修复,我已经得到了问题Cannot deploy Next.js to Netlify. Deploy failed due to an error in @netlify/plugin-nextjs plugin

这是我的日志

12:10:08 PM: Build ready to start
12:10:11 PM: build-image version: a49edbc55fc722f80f6b85963a5060f8d043a844 (focal)
12:10:11 PM: build-image tag: v4.8.1
12:10:11 PM: buildbot version: 4d0ac5fd74188fe527fa2a661368485be00b8be6
12:10:12 PM: Fetching cached dependencies
12:10:12 PM: Failed to fetch cache, continuing with build
12:10:12 PM: Starting to prepare the repo for build
12:10:12 PM: No cached dependencies found. Cloning fresh repo
12:10:12 PM: git clone https://github.com/farishelmipermana/nextjs-portfolio
12:10:12 PM: Preparing Git Reference refs/heads/master
12:10:13 PM: Parsing package.json dependencies
12:10:14 PM: Starting build script
12:10:14 PM: Installing dependencies
12:10:14 PM: Python version set to 2.7
12:10:14 PM: v16.15.1 is already installed.
12:10:15 PM: Now using node v16.15.1 (npm v8.11.0)
12:10:15 PM: Started restoring cached build plugins
12:10:15 PM: Finished restoring cached build plugins
12:10:15 PM: Attempting ruby version 2.7.2, read from environment
12:10:16 PM: Using ruby version 2.7.2
12:10:16 PM: Using PHP version 8.0
12:10:16 PM: Started restoring cached yarn cache
12:10:16 PM: Finished restoring cached yarn cache
12:10:17 PM: No yarn workspaces detected
12:10:17 PM: Started restoring cached node modules
12:10:17 PM: Finished restoring cached node modules
12:10:17 PM: Installing NPM modules using Yarn version 1.22.10
12:10:17 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
12:10:17 PM: npm WARN config location in the cache, and they are managed by
12:10:17 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
12:10:17 PM: yarn install v1.22.10
12:10:18 PM: 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.
12:10:18 PM: [1/4] Resolving packages...
12:10:18 PM: [2/4] Fetching packages...
12:10:25 PM: info @next/swc-win32-x64-msvc@12.1.6: The platform "linux" is incompatible with this module.
12:10:25 PM: info "@next/swc-win32-x64-msvc@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: info @next/swc-android-arm64@12.1.6: The platform "linux" is incompatible with this module.
12:10:25 PM: info "@next/swc-android-arm64@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: info @next/swc-android-arm64@12.1.6: The CPU architecture "x64" is incompatible with this module.
12:10:25 PM: info @next/swc-android-arm-eabi@12.1.6: The platform "linux" is incompatible with this module.
12:10:25 PM: info "@next/swc-android-arm-eabi@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: info @next/swc-android-arm-eabi@12.1.6: The CPU architecture "x64" is incompatible with this module.
12:10:25 PM: info @next/swc-darwin-arm64@12.1.6: The platform "linux" is incompatible with this module.
12:10:25 PM: info "@next/swc-darwin-arm64@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: info @next/swc-darwin-arm64@12.1.6: The CPU architecture "x64" is incompatible with this module.
12:10:25 PM: info @next/swc-linux-arm-gnueabihf@12.1.6: The CPU architecture "x64" is incompatible with this module.
12:10:25 PM: info "@next/swc-linux-arm-gnueabihf@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: info @next/swc-linux-arm64-gnu@12.1.6: The CPU architecture "x64" is incompatible with this module.
12:10:25 PM: info "@next/swc-linux-arm64-gnu@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: info @next/swc-darwin-x64@12.1.6: The platform "linux" is incompatible with this module.
12:10:25 PM: info "@next/swc-darwin-x64@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: info @next/swc-win32-ia32-msvc@12.1.6: The platform "linux" is incompatible with this module.
12:10:25 PM: info "@next/swc-win32-ia32-msvc@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: info @next/swc-win32-ia32-msvc@12.1.6: The CPU architecture "x64" is incompatible with this module.
12:10:25 PM: info @next/swc-win32-arm64-msvc@12.1.6: The platform "linux" is incompatible with this module.
12:10:25 PM: info "@next/swc-win32-arm64-msvc@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: info @next/swc-win32-arm64-msvc@12.1.6: The CPU architecture "x64" is incompatible with this module.
12:10:25 PM: info @next/swc-linux-arm64-musl@12.1.6: The CPU architecture "x64" is incompatible with this module.
12:10:25 PM: info "@next/swc-linux-arm64-musl@12.1.6" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: info fsevents@2.3.2: The platform "linux" is incompatible with this module.
12:10:25 PM: info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
12:10:25 PM: [3/4] Linking dependencies...
12:10:25 PM: [4/4] Building fresh packages...
12:10:25 PM: success Saved lockfile.
12:10:25 PM: Done in 8.02s.
12:10:25 PM: NPM modules installed using Yarn
12:10:26 PM: Started restoring cached go cache
12:10:26 PM: Finished restoring cached go cache
12:10:26 PM: Installing Go version 1.17 (requested 1.17)
12:10:31 PM: unset GOOS;
12:10:31 PM: unset GOARCH;
12:10:31 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
12:10:31 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
12:10:31 PM: go version >&2;
12:10:31 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
12:10:31 PM: go version go1.17 linux/amd64
12:10:31 PM: Installing missing commands
12:10:31 PM: Verify run directory
12:10:33 PM: ​
12:10:33 PM: ────────────────────────────────────────────────────────────────
12:10:33 PM:   Netlify Build                                                 
12:10:33 PM: ────────────────────────────────────────────────────────────────
12:10:33 PM: ​
12:10:33 PM: ❯ Version
12:10:33 PM:   @netlify/build 27.1.6
12:10:33 PM: ​
12:10:33 PM: ❯ Flags
12:10:33 PM:   baseRelDir: true
12:10:33 PM:   buildId: 62b3f5b0d3c7f33c0246be8c
12:10:33 PM:   deployId: 62b3f5b0d3c7f33c0246be8e
12:10:33 PM: ​
12:10:33 PM: ❯ Current directory
12:10:33 PM:   /opt/build/repo
12:10:33 PM: ​
12:10:33 PM: ❯ Config file
12:10:33 PM:   No config file was defined: using default values.
12:10:33 PM: ​
12:10:33 PM: ❯ Context
12:10:33 PM:   production
12:10:33 PM: ​
12:10:33 PM: ❯ Installing plugins
12:10:33 PM:    - @netlify/plugin-nextjs@4.9.1
12:10:43 PM: ​
12:10:43 PM: ❯ Loading plugins
12:10:43 PM:    - @netlify/plugin-nextjs@4.9.1 from Netlify app
12:10:45 PM: ​
12:10:45 PM: ────────────────────────────────────────────────────────────────
12:10:45 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
12:10:45 PM: ────────────────────────────────────────────────────────────────
12:10:45 PM: ​
12:10:45 PM: No Next.js cache to restore.
12:10:45 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
12:10:45 PM: ​
12:10:45 PM: (@netlify/plugin-nextjs onPreBuild completed in 24ms)
12:10:45 PM: ​
12:10:45 PM: ────────────────────────────────────────────────────────────────
12:10:45 PM:   2. Build command from Netlify app                             
12:10:45 PM: ────────────────────────────────────────────────────────────────
12:10:45 PM: ​
12:10:45 PM: $ yarn build && next export
12:10:45 PM: yarn run v1.22.10
12:10:45 PM: $ next build
12:10:46 PM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
12:10:46 PM: info  - Checking validity of types...
12:10:46 PM: warn  - No ESLint configuration detected. Run next lint to begin setup
12:10:46 PM: info  - Creating an optimized production build...
12:10:59 PM: info  - Compiled successfully
12:10:59 PM: info  - Collecting page data...
12:11:02 PM: info  - Generating static pages (0/6)
12:11:02 PM: info  - Generating static pages (1/6)
12:11:02 PM: info  - Generating static pages (2/6)
12:11:02 PM: info  - Generating static pages (4/6)
12:11:02 PM: info  - Generating static pages (6/6)
12:11:03 PM: info  - Finalizing page optimization...
12:11:03 PM: Page                                       Size     First Load JS
12:11:03 PM: ┌ ○ /                                      1.86 kB        79.5 kB
12:11:03 PM: ├   /_app                                  0 B            75.2 kB
12:11:03 PM: ├ ○ /404                                   193 B          75.4 kB
12:11:03 PM: ├ ○ /about                                 813 B          78.4 kB
12:11:03 PM: ├ ○ /contact                               728 B          78.3 kB
12:11:03 PM: └ ○ /portfolio                             747 B          78.4 kB
12:11:03 PM: + First Load JS shared by all              75.2 kB
12:11:03 PM:   ├ chunks/framework-4556c45dd113b893.js   45.2 kB
12:11:03 PM:   ├ chunks/main-d8b1ff545a609496.js        28.6 kB
12:11:03 PM:   ├ chunks/pages/_app-fb3a3036b08bee65.js  508 B
12:11:03 PM:   ├ chunks/webpack-69bfa6990bb9e155.js     769 B
12:11:03 PM:   └ css/2ab3fddc65372c75.css               752 B
12:11:03 PM: ○  (Static)  automatically rendered as static HTML (uses no initial props)
12:11:03 PM: Done in 17.71s.
12:11:03 PM: info  - using build directory: /opt/build/repo/.next
12:11:03 PM: info  - Copying "static build" directory
12:11:03 PM: info  - No "exportPathMap" found in "undefined". Generating map from "./pages"
12:11:03 PM: info  - Launching 7 workers
12:11:03 PM: info  - Exporting (0/5)
12:11:03 PM: info  - Copying "public" directory
12:11:04 PM: info  - Exporting (1/5)
12:11:04 PM: info  - Exporting (2/5)
12:11:04 PM: info  - Exporting (3/5)
12:11:04 PM: info  - Exporting (5/5)
12:11:04 PM: Export successful. Files written to /opt/build/repo/out
12:11:04 PM: ​
12:11:04 PM: (build.command completed in 19.4s)
12:11:04 PM: ​
12:11:04 PM: ────────────────────────────────────────────────────────────────
12:11:04 PM:   3. @netlify/plugin-nextjs (onBuild event)                     
12:11:04 PM: ────────────────────────────────────────────────────────────────
12:11:04 PM: ​
12:11:04 PM: ​
12:11:04 PM: ────────────────────────────────────────────────────────────────
12:11:04 PM:   Plugin "@netlify/plugin-nextjs" failed                        
12:11:04 PM: ────────────────────────────────────────────────────────────────
12:11:04 PM: ​
12:11:04 PM:   Error message
12:11:04 PM:   Error: The directory "/opt/build/repo/out" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
12:11:04 PM:   Your publish directory is set to "out", but in most cases it should be ".next".
12:11:04 PM:   If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
12:11:04 PM: ​
12:11:04 PM:   Plugin details
12:11:04 PM:   Package:        @netlify/plugin-nextjs
12:11:04 PM:   Version:        4.9.1
12:11:04 PM:   Repository:     git+https://github.com/netlify/netlify-plugin-nextjs.git
12:11:04 PM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
12:11:04 PM:   Report issues:  https://github.com/netlify/netlify-plugin-nextjs/issues
12:11:04 PM: ​
12:11:04 PM:   Error location
12:11:04 PM:   In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app
12:11:04 PM:       at checkNextSiteHasBuilt (/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/verification.js:72:16)
12:11:04 PM:       at onBuild (/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/index.js:41:50)
12:11:04 PM: ​
12:11:04 PM:   Resolved config
12:11:04 PM:   build:
12:11:04 PM:     command: yarn build && next export
12:11:04 PM:     commandOrigin: ui
12:11:04 PM:     environment:
12:11:04 PM:       - NEXT_PRIVATE_TARGET
12:11:04 PM:     publish: /opt/build/repo/out
12:11:04 PM:     publishOrigin: ui
12:11:04 PM:   plugins:
12:11:04 PM:     - inputs: {}
12:11:04 PM:       origin: ui
12:11:04 PM:       package: '@netlify/plugin-nextjs'
12:11:05 PM: Caching artifacts
12:11:05 PM: Started saving node modules
12:11:05 PM: Finished saving node modules
12:11:05 PM: Started saving build plugins
12:11:05 PM: Finished saving build plugins
12:11:05 PM: Started saving yarn cache
12:11:05 PM: Finished saving yarn cache
12:11:05 PM: Started saving pip cache
12:11:05 PM: Finished saving pip cache
12:11:05 PM: Started saving emacs cask dependencies
12:11:05 PM: Finished saving emacs cask dependencies
12:11:05 PM: Started saving maven dependencies
12:11:05 PM: Finished saving maven dependencies
12:11:05 PM: Started saving boot dependencies
12:11:05 PM: Finished saving boot dependencies
12:11:05 PM: Started saving rust rustup cache
12:11:05 PM: Finished saving rust rustup cache
12:11:05 PM: Started saving go dependencies
12:11:05 PM: Finished saving go dependencies
12:11:07 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:11:07 PM: Creating deploy upload records
12:11:07 PM: Failing build: Failed to build site
12:11:07 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
12:11:07 PM: Finished processing build request in 55.750494271s

我尝试将公共目录设置为out,但我仍然得到这样的错误Cannot deploy Next.js to Netlify. Deploy failed due to an error in @netlify/plugin-nextjs plugin

我也删除了netlify的所有插件,但错误仍然发生像这样的Cannot deploy Next.js to Netlify. Deploy failed due to an error in @netlify/plugin-nextjs plugin

谢谢你的帮助

TL;DR:您需要在netflix UI中添加NETLIFY_NEXT_PLUGIN_SKIP环境变量,其值为true。然后可以将发布目录设置为out,这样就可以了。

根据您的构建命令,您正在使用Next.js的静态导出功能。这需要在netflix上进行特殊配置,如下所示:https://github.com/netlify/netlify-plugin-nextjs#use-with-next-export

最新更新