You need to enable JavaScript to run this app. Next.js使用next-compose-plugins构建报interface保留字错误如何解决
优惠活动
大模型
产品
解决方案
定价
更多

Next.js使用next-compose-plugins构建报interface保留字错误如何解决

问题排查与解决方案

1. 核心配置语法错误

你当前的next-compose-plugins用法错误,该插件要求第一个参数传入所有插件组成的单个数组,你将每个插件单独拆分为独立数组参数,导致所有插件未生效,对应文件类型的loader完全没有加载,因此TS文件中的interface关键字无法被识别转译,直接抛出保留字报错。

2. 插件拼写错误

你代码中写的withSaas为拼写错误,正确的Sass插件导出名是withSass,拼写错误会导致Sass相关loader也未注册。

3. 补充react-jss与转译配置

如果你使用的react-jss或其他第三方依赖包含未转译的TS代码,需要确认withTM(next-transpile-modules)的入参已经添加了对应依赖包名,否则外部依赖中的TS代码也会触发相同报错。


修正后的配置参考

// 注意先确认你导入的Sass插件名是否为withSass,修正拼写
const withPlugins = require('next-compose-plugins');
// 其他插件导入保持不变

const nextConfig = {
  distDir: "../../build",
  async headers() {
    return [
      {
        source: '*',
        headers: [
          {
            key: 'x-custom-header',
            value: 'my custom header value',
          },
          {
            key: 'x-another-custom-header',
            value: 'my other custom header value',
          },
        ],
      },
    ]
  },
  webpack: (config, { isServer }) => {
    config.optimization.minimizer = [];
    config.optimization.minimizer.push(new OptimizeCSSAssetsPlugin({}));
    if (!isServer) {
      // 注意确认此处Sentry别名路径是否正确,路径中的空格可能导致解析失败
      config.resolve.alias["@sentry/node"] = "@Sentry (Legacy)/browser";
    }
    return config;
  },
}

// 正确的withPlugins调用方式:所有插件放在第一个数组参数中,第二个参数传nextConfig
module.exports = withPlugins(
  [withCSS, withSass, withImages, nextSourceMaps, withTM],
  nextConfig
);

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.19 06:06:01