You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: HMR not working in lazy import components #11324
When booting in devServer mode, in the initial compile the chunk explicit-chunk-name.js contains ../containers/Container, but after an HMR recompile, suddenly explicit-chunk-name.js reduces in size by half and no longer contains ../containers/Container.
This is persistent after refreshes and requires us to restart the rspack process
Reacted by Kartik Jain, Jacob Waller, jheng-jie, Jayden, Irena D, Boston Dell-Vandenberg, pratosh-ss and Diego Bogo
@mrleidesen I have tried rspack and webpack, they both failed to do hot replacing with the same error.
In your case, after adding the Button component, bundler will create a new chunk named vendors-node_modules.xxxx.js. IMO, this chunk should be expected to present in hotupdate main file (xxx.[hash].hotupdate.json); but it doesn't show up, so requiring to modules in the vendor chunk will throw a undefined factory error.
I will make PRs to webpack and rspack, it takes time.
@mrleidesen I have tried rspack and webpack, they both failed to do hot replacing with the same error.
In your case, after adding the Button component, bundler will create a new chunk named vendors-node_modules.xxxx.js. IMO, this chunk should be expected to present in hotupdate main file (xxx.[hash].hotupdate.json); but it doesn't show up, so requiring to modules in the vendor chunk will throw a undefined factory error.
I will make PRs to webpack and rspack, it takes time.
Since @litenjacob and myself have reported this as working in v1.4.10 and broken since v1.4.11, is there any PR in that version that might have caused it?
I've also tested it in a few other cases:
bundler
version
works
rspack
1.4.10
yes 👍
rspack
1.4.11
no :(
rspack
1.4.11
no :(
rspack
1.5.0-beta.0
no :(
webpack
5.97.1
yes 👍
Because it works in Webpack, I'm wondering if we are facing the same issue, since you mention that what you reproduced also fails in webpack.
In my initial comment I missed adding some additional clues. There were certain files which caused a full page reload so I only saw the undefined factory error, but on actual hot reloading (without full page refresh), I see some additional logs which might be interesting:
Then after that, I get:
[HMR] Updated modules:
[HMR] - ../../container/components/SomeComponent.tsx
// 25+ more files
[HMR] App is up to date.
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check your code at SomeComponent.tsx:13.
Some other things to note:
manifest.js is our runtime chunk (rspackConfig.optimization.runtimeChunk.name = 'manifest')
In Webpack, for [HMR] Updated modules: I only see 1 module vs 25+ in rspack@1.4.11
In rspack@1.4.10, for [HMR] Updated modules: I only see 1 module vs 25+ in rspack@1.4.11
In rspack@1.4.11, the explicit-chunk-name.js does get an explicit-chunk-name.hot-update.js, but contains AnotherComponent.ts, notSomeComponent.tsx
In rspack@1.4.10, I see manifest.hot-update.js, manifest.hot-update.json and another-chunk-name.hot-update.js
In rspack@1.4.11, I see manifest.hot-update.js, manifest.hot-update.json, another-chunk-name.hot-update.js, explicit-chunk-name.hot-update.js (this is the bugged one!) AND 3 additional other {chunkName}.hot-update.js,
In short, when comparing 1.4.11 vs 1.4.10, a single file change seems to affect a lot more HMR modules and HMR chunk.
I'm unable to share private code here, but if it helps, I'm on the Rspack Discord as well (username PostmanPat), perhaps we can jump on a screensharing call to debug further
Reacted by undefined, Jacob Waller and Boston Dell-Vandenberg
Reacted by Jacob Waller and Boston Dell-Vandenberg
I'm also seeing this issue on 1.4.11 and 1.5.0, and no issues on 1.4.10. The initial build works great, but any small change to a single file results in a rebuild that seems to be affecting a large number of unrelated modules, and results in very different outputs that will not run.
I'm also seeing this issue on 1.4.11 and 1.5.0, and no issues on 1.4.10. The initial build works great, but any small change to a single file results in a rebuild that seems to be affecting a large number of unrelated modules, and results in very different outputs that will not run.
Is there any information I could provide to help this issue further @stormslowly ?
Currently, I can't make a conclusion yet. According the orignal reproduce codesandbox.io/p/devbox/7npnc7, a workaround is to disable splitChunks in dev mode.
During development, splitChunks may move some modules between chunks or create a new chunk for newly introduced modules.
If a new chunk is generated, its modules may fail to load correctly during HMR. When those modules are required, it triggers an undefined factory error.
Detailed Explanation
Initially (before importing Antd Button):
Only two chunks exist: main.js and src_lazyItem_jsx.js.
After importing Antd Button in LazyItem.js:
src_lazyItem_jsx.js grows in size.
It gets split into:
src_lazyItem_jsx.js
A new vendors_xxxx.js chunk containing required node_modules, including Antd’s Button code.
Since CodeSplitting is involved:
App.js (which dynamically loads LazyItem.jsx) must now ensure bothsrc_lazyItem_jsx.js and vendors_xxxx.js are loaded, instead of just src_lazyItem_jsx.js.
Therefore, in the next HMR cycle, both App.jsx and LazyItem.jsx are re-executed via *.hotupdate.js.
Problem:
App.jsx loads chunks asynchronously, but execution of new code happens synchronously.
This means when LazyItem.jsx executes, vendors_xxxx.js may not yet be ready.
As a result, we hit the error: undefined factory ....node_modules/antd/es/button/index.js
This undefined factory is expected under such circumstances, and the only safe recovery is a full reload.
The unexpected part is that the error fails silently.
Why It Fails Silently
When React Refresh is enabled, all HMR errors are routed to webpackHot.accept.
If refreshOverlay is disabled (default in @rspack/plugin-react-refresh), runtime errors during HMR are suppressed.
If refreshOverlay is enabled, things still don’t work as expected:
Two hot update modules (LazyItem.jsx and App.jsx) need to be applied.
When LazyItem.jsx executes first, its error is passed to refreshOverlay.handleRuntimeError(error).
But since overlay rendering is debounced, the error display is delayed.
Then, when App.jsx hot-update runs, it clears runtime errors, dismissing the overlay before it even shows.
Result: No error is visible to the developer.
Solutions
When an undefined factory error occurs, the only reliable solution is to reload.
To support this, we need to let @rspack/plugin-react-refresh recognize such errors.
Activity
chenjiahan commentedon Aug 7, 2025
I suspected this was an issue with the Rspack HMR runtime, so I transferred the issue to the Rspack repository.
litenjacob commentedon Aug 8, 2025
For us this case seemed to be working in
1.4.10but brake in1.4.11with anundefined factoryerror.patricksevat commentedon Aug 11, 2025
Hi, we're facing
undefined factoryas well, what we are noticing is that withThere is a certain dynamic import with this shape:
const LazyComponent = lazy(() => import(/* webpackChunkName: "explicit-chunk-name" */ '../containers/Container'));When booting in devServer mode, in the initial compile the chunk
explicit-chunk-name.jscontains../containers/Container, but after an HMR recompile, suddenlyexplicit-chunk-name.jsreduces in size by half and no longer contains../containers/Container.This is persistent after refreshes and requires us to restart the rspack process
stormslowly commentedon Aug 12, 2025
@mrleidesen I have tried rspack and webpack, they both failed to do hot replacing with the same error.
In your case, after adding the
Buttoncomponent, bundler will create a new chunk namedvendors-node_modules.xxxx.js. IMO, this chunk should be expected to present in hotupdate main file (xxx.[hash].hotupdate.json); but it doesn't show up, so requiring to modules in the vendor chunk will throw a undefined factory error.I will make PRs to webpack and rspack, it takes time.
mrleidesen commentedon Aug 14, 2025
Thank you!
patricksevat commentedon Aug 14, 2025
@stormslowly Thanks for picking this up!
Since @litenjacob and myself have reported this as working in v1.4.10 and broken since v1.4.11, is there any PR in that version that might have caused it?
I've also tested it in a few other cases:
Because it works in Webpack, I'm wondering if we are facing the same issue, since you mention that what you reproduced also fails in webpack.
In my initial comment I missed adding some additional clues. There were certain files which caused a full page reload so I only saw the
undefined factoryerror, but on actual hot reloading (without full page refresh), I see some additional logs which might be interesting:Then after that, I get:
Some other things to note:
manifest.jsis our runtime chunk (rspackConfig.optimization.runtimeChunk.name = 'manifest')[HMR] Updated modules:I only see 1 module vs 25+ in rspack@1.4.11[HMR] Updated modules:I only see 1 module vs 25+ in rspack@1.4.11explicit-chunk-name.jsdoes get anexplicit-chunk-name.hot-update.js, but containsAnotherComponent.ts, notSomeComponent.tsxmanifest.hot-update.js,manifest.hot-update.jsonandanother-chunk-name.hot-update.jsmanifest.hot-update.js,manifest.hot-update.json,another-chunk-name.hot-update.js,explicit-chunk-name.hot-update.js(this is the bugged one!) AND 3 additional other{chunkName}.hot-update.js,In short, when comparing 1.4.11 vs 1.4.10, a single file change seems to affect a lot more HMR modules and HMR chunk.
I'm unable to share private code here, but if it helps, I'm on the Rspack Discord as well (username
PostmanPat), perhaps we can jump on a screensharing call to debug furthermrleidesen commentedon Aug 15, 2025
This works for me!
I mean "@rspack/core": "1.4.10" , not "rspack"
patricksevat commentedon Aug 27, 2025
This is still an issue on 1.5.0, unfortunately.
Is there any information I could provide to help this issue further @stormslowly ?
JMStewart commentedon Aug 27, 2025
I'm also seeing this issue on 1.4.11 and 1.5.0, and no issues on 1.4.10. The initial build works great, but any small change to a single file results in a rebuild that seems to be affecting a large number of unrelated modules, and results in very different outputs that will not run.
stormslowly commentedon Aug 28, 2025
could plz share reproduce repo?
stormslowly commentedon Aug 28, 2025
Currently, I can't make a conclusion yet. According the orignal reproduce codesandbox.io/p/devbox/7npnc7, a workaround is to disable
splitChunksin dev mode.optimization: { splitChunks: false }there is a example
@patricksevat could plz help to verify this workaround is working for you?
stormslowly commentedon Aug 28, 2025
@JMStewart i don't think it's the right way to overrides. the rspack is deprecated for years.
I have noticed that you're chinese too. Could plz join our Feishu Group for easy discuss this problem?
patricksevat commentedon Aug 28, 2025
I tried this on rspack@1.5.0:
I'm still seeing
undefined factoryerrors, although I'm seeing a different one than I saw before.patricksevat commentedon Aug 29, 2025
The workaround mentioned by @JSerFeng in #11530 (comment) seems to work for me in rspack@1.5.1 🥳 :
stormslowly commentedon Sep 1, 2025
So it's not the same case with @mrleidesen , I will focus on the original case.
stormslowly commentedon Sep 5, 2025
Root Cause Analysis
Simple Description
During development,
splitChunksmay move some modules between chunks or create a new chunk for newly introduced modules.If a new chunk is generated, its modules may fail to load correctly during HMR. When those modules are required, it triggers an undefined factory error.
Detailed Explanation
Initially (before importing Antd
Button):main.jsandsrc_lazyItem_jsx.js.After importing Antd
ButtoninLazyItem.js:src_lazyItem_jsx.jsgrows in size.src_lazyItem_jsx.jsvendors_xxxx.jschunk containing requirednode_modules, including Antd’sButtoncode.Since
CodeSplittingis involved:App.js(which dynamically loadsLazyItem.jsx) must now ensure bothsrc_lazyItem_jsx.jsandvendors_xxxx.jsare loaded, instead of justsrc_lazyItem_jsx.js.App.jsxandLazyItem.jsxare re-executed via*.hotupdate.js.Problem:
App.jsxloads chunks asynchronously, but execution of new code happens synchronously.LazyItem.jsxexecutes,vendors_xxxx.jsmay not yet be ready.undefined factory ....node_modules/antd/es/button/index.jsThis undefined factory is expected under such circumstances, and the only safe recovery is a full reload.
The unexpected part is that the error fails silently.
Why It Fails Silently
When React Refresh is enabled, all HMR errors are routed to
webpackHot.accept.refreshOverlayis disabled (default in@rspack/plugin-react-refresh), runtime errors during HMR are suppressed.refreshOverlayis enabled, things still don’t work as expected:LazyItem.jsxandApp.jsx) need to be applied.LazyItem.jsxexecutes first, its error is passed torefreshOverlay.handleRuntimeError(error).App.jsxhot-update runs, it clears runtime errors, dismissing the overlay before it even shows.Result: No error is visible to the developer.
Solutions
When an undefined factory error occurs, the only reliable solution is to reload.
To support this, we need to let
@rspack/plugin-react-refreshrecognize such errors.With
reloadOnRuntimeErrorenabled,@rspack/plugin-react-refreshwill trigger a full reload onundefined factoryerrors.stormslowly commentedon Sep 11, 2025
close by rstackjs/rspack-plugin-react-refresh#50 and #11584
zhangchao828 commentedon Oct 17, 2025
@stormslowly 最新版本1.5.8还是会报这个错,是和模块联邦一起使用时
stormslowly commentedon Oct 28, 2025
@zhangchao828
可以给我一个复现的 repo 吗?
test(start-plugin-core): pin a route's first server fn breaking its c…