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

Next.js报错:next.config.js中target属性已不再支持,求解决方案

解决Next.js中target属性废弃的报错问题

问题原因

新版Next.js已移除target配置属性,原target: "serverless"写法不再被支持,需替换为output选项来指定构建输出类型。

修改方案

直接移除target: "serverless",根据部署需求添加对应的output配置:

  • 若需部署到无服务器平台(如AWS Lambda、Vercel),使用output: "standalone"(生成最小化独立服务包)
  • 若需纯静态导出(无服务端功能),使用output: "export"

修改后的完整配置代码

const withBundleAnalyzer = require("@next/bundle-analyzer")({
  enabled: process.env.ANALYZE === "true",
});

module.exports = withBundleAnalyzer({
  output: "standalone", // 替换原target配置
  env: {
    BASE_URL: process.env.BASE_URL,
  },

  webpack(conf) {
    conf.module.rules.push({
      test: /\.svg$/,
      use: [
        {
          loader: "@svgr/webpack",
          options: {
            svgoConfig: {
              plugins: [
                {
                  // Enable figma's wrong mask-type attribute work
                  removeRasterImages: false,
                  removeStyleElement: false,
                  removeUnknownsAndDefaults: false,
                  // Enable svgr's svg to fill the size
                  removeViewBox: false,
                },
              ],
            },
          },
        },
      ],
    });
    conf.resolve.modules.push(__dirname);
    return conf;
  },
});

注意事项

  • 保存修改后,重启开发服务或重新执行构建命令即可生效
  • 若使用output: "export",需确保应用不依赖服务端渲染、API路由等仅在Node.js环境运行的功能

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 18:10:48