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

为何RSPack未替换变量名?出现'module'标识符重复声明语法错误

用RSPack替换React-scripts后出现变量冲突报错:Identifier 'module' has already been declared

我正尝试用RSPack替换旧版React-scripts构建流程,目前已完成配置并可执行构建,但在浏览器中出现变量冲突问题——推测和代码拆分有关,变量未被正确重命名,导致多处const module声明冲突,具体报错为:
Uncaught SyntaxError: Identifier 'module' has already been declared

相关截图说明:

  • 控制台报错截图:显示上述语法错误信息
  • 代码行截图:可见多处重复的const module声明语句

当前使用的rsbuild.config.ts配置如下:

import { defineConfig, loadEnv } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginEslint } from '@rsbuild/plugin-eslint';

const { publicVars, rawPublicVars } = loadEnv({ prefixes: ['REACT_APP_'] });

export default defineConfig({
  plugins: [pluginReact()],
  html: {
    template: './public/index.html',
  },
  output: {
    distPath: {
      root: 'build',
    },
    polyfill: 'usage',
  },
  source: {
    define: { ...publicVars, 'process.env': JSON.stringify(rawPublicVars) },
  },
});

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 21:17:36