Skip to content

[Bug]: duplicate modules in dev build with persistent cache #12852

@escaton

Description

@escaton

System Info

  System:
    OS: macOS 15.7.2
    CPU: (14) arm64 Apple M4 Pro
    Memory: 2.47 GB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.12.0 - /Users/escaton/.nvm/versions/node/v24.12.0/bin/node
    npm: 11.6.2 - /Users/escaton/.nvm/versions/node/v24.12.0/bin/npm
    bun: 1.3.6 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 144.0.7559.97
    Firefox: 147.0.1
    Safari: 26.1
  npmPackages:
    @rsbuild/core: 1.7.2 => 1.7.2 
    @rsbuild/plugin-type-check: 1.3.3 => 1.3.3 
    @rsbuild/plugin-vue: 1.2.3 => 1.2.3 

Details

I'm using rsbuild, and my cache config looks like this (rsbuild inspect)

cache: {
  type: 'persistent',
  version: 'web-development',
  storage: {
    type: 'filesystem',
    directory: '/Users/escaton/Projects/playgama/portal-frontend-vue/node_modules/.cache/rspack'
  },
  buildDependencies: [
    '/Users/escaton/Projects/playgama/portal-frontend-vue/package.json',
    '/Users/escaton/Projects/playgama/portal-frontend-vue/tsconfig.json',
    '/Users/escaton/Projects/playgama/portal-frontend-vue/rsbuild.config.ts',
    '/Users/escaton/Projects/playgama/portal-frontend-vue/.browserslistrc',
    '/Users/escaton/Projects/playgama/portal-frontend-vue/.env'
  ]
},

which is a default set by rsbuild.

Sometimes when I switch branches, or change anything in rsbuild.config, and run rsbuild dev I got an invalid build of my app. It crashes like there are duplicates of modules that were supposed to be singletons. Indeed when I inspected built index.js I see multiple duplicates of some modules like

"./src/i18n/i18n.ts?abb2": (function (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
...
},
"./src/i18n/i18n.ts?a942": (function (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
...
},

After I remove the cache rm ./node_modules/.cache/rspack
the content becomes

"./src/i18n/i18n.ts": (function (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
...
},

I did't recognize any pattern of why certain modules got duplicated and some not, and don't know how to dig deeper. For now I just remove cache and move on, but that is annoying.

I understand it is pretty vague bug report, but I have no idea how to make a small repro.
Can you at least tell me how is it even possible to have multiple copies of same module with those ?XXXX queries, so I can try to investigate further.

Reproduce link

No response

Reproduce Steps

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions