You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Next.js应用报错:next export已移除,需改用output: export配置

解决Next.js 14.0.4中"The 'next export' command has been removed..."报错问题

问题根源

在Next.js 13+(含14.0.4)版本中,next export命令已被废弃,官方要求通过next.config.js中的output: 'export'配置实现静态导出。此时直接执行next build就会自动完成静态文件生成,单独执行next export命令会触发报错,这也是你当前问题的核心原因。

具体修复步骤

  1. 移除无效的next export命令
    打开package.json,删除你添加的"export": "next export"配置,确保scripts部分保持如下结构:

    {
      "scripts": {
        "dev": "next dev",
        "build": "next build",
        "start": "next start",
        "lint": "next lint"
      }
    }
    
  2. 确认next.config.js配置有效性
    你的现有配置已经符合静态导出要求,确保output: 'export'和images.unoptimized: true(静态导出时必须关闭图片优化)配置正确:

    /**
     * @type {import('next').NextConfig}
     */
    const nextConfig = {
      output: 'export',
      images: {
        unoptimized: true
      }
      // 可选配置可根据需求开启
      // trailingSlash: true,
      // skipTrailingSlashRedirect: true,
      // distDir: 'dist',
    }
    
    module.exports = nextConfig
    
  3. 执行正确的构建命令
    在终端运行以下命令完成静态导出:

    npm run build
    

    执行完成后,Next.js会自动在项目根目录生成out文件夹(或你通过distDir配置的自定义目录),该文件夹内的文件即可直接部署到静态托管平台。

额外注意事项

  • 静态导出模式不支持Server Components、API Routes、增量静态再生等特性,需确保项目未依赖这些功能。
  • 若部署后出现路径匹配问题,可尝试开启trailingSlash: true配置,让所有路由以/结尾,适配多数静态托管平台的路径规则。

内容的提问来源于stack exchange,提问作者Anshita Jawney

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 18:22:52