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
相关产品推荐
相关产品推荐

