serverComponentsExternalPackages

伺服器元件 (Server Components)路由處理器 (Route Handlers) 中使用的依賴項會自動被 Next.js 打包。

如果某個依賴項使用了 Node.js 的特定功能,您可以選擇讓特定依賴項不參與伺服器元件 (Server Components) 的打包流程,直接使用原生 Node.js 的 require

next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: ['@acme/ui'],
  },
}

module.exports = nextConfig

Next.js 已內建一份常用套件清單,這些套件目前正在進行相容性適配並會自動排除打包:

  • @aws-sdk/client-s3
  • @aws-sdk/s3-presigned-post
  • @blockfrost/blockfrost-js
  • @libsql/client
  • @jpg-store/lucid-cardano
  • @mikro-orm/core
  • @mikro-orm/knex
  • @prisma/client
  • @sentry/nextjs
  • @sentry/node
  • @swc/core
  • argon2
  • autoprefixer
  • aws-crt
  • bcrypt
  • better-sqlite3
  • canvas
  • cpu-features
  • cypress
  • eslint
  • express
  • firebase-admin
  • jest
  • jsdom
  • libsql
  • lodash
  • mdx-bundler
  • mongodb
  • mongoose
  • next-mdx-remote
  • next-seo
  • payload
  • pg
  • playwright
  • postcss
  • prettier
  • prisma
  • puppeteer
  • rimraf
  • sharp
  • shiki
  • sqlite3
  • tailwindcss
  • ts-node
  • typescript
  • vscode-oniguruma
  • webpack