#14744·meteor

Rspack production: dynamic-import() chunks are requested without ROOT_URL_PATH_PREFIX (ChunkLoadError under a path-prefixed ROOT_URL)

Author: dupontbertrandCreated Sep 12, 2026Updated Sep 14, 2026
Labelsmodern-build-stack

Encountered while building a Meteor 3.5.2 + Rspack regression bench; written and opened by Claude Code after review by the author (@dupontbertrand).

Summary

In a production build under Rspack, dynamically-imported (code-split) chunks are requested without the ROOT_URL_PATH_PREFIX. When the app is served under a path-prefixed ROOT_URL (e.g. http://host/ks), the main bundle is correctly served under /ks/…, but a chunk fetched by import() is requested at /build-chunks/<n>.<hash>.js — with no /ks — and 404s, producing a ChunkLoadError.

The chunk-loader publicPath in the production build omits ROOT_URL_PATH_PREFIX.

Environment

Reproduction

Confirmed on the reference (published Meteor 3.5.2). The checkout/port status was not measured separately (the prefixed prod variant was only exercised against the reference toolchain).

  1. In a Meteor 3.5.2 + Rspack app, add a module that is loaded via a dynamic import, e.g.:
    // client triggers it at runtime
    const mod = await import('/imports/dynamic-chunk.js');
    
    so Rspack emits a separate chunk under build-chunks/.
  2. Build for production: meteor build --directory /tmp/out --server-only.
  3. Serve the bundle with a path-prefixed root URL:
    ROOT_URL=http://localhost:3000/ks MONGO_URL=… PORT=3000 node /tmp/out/bundle/main.js
    
  4. Load the app at http://localhost:3000/ks/ and trigger the import().

Observed: the main bundle loads from /ks/<hash>.js (correct), but the dynamic chunk is fetched from /build-chunks/<n>.<hash>.js (no /ks) → 404 → ChunkLoadError:

ChunkLoadError: Loading chunk 430 failed.
(error: http://localhost:3000/build-chunks/430.<hash>.js)
    at … (http://localhost:3000/ks/<hash>.js?meteor_js_resource=true:…)

Note that the main bundle URL in the stack trace does carry /ks, confirming the app itself is correctly prefixed — only the code-split chunk loader is not. Other path-prefix behaviours work in this same prod run (the served boilerplate and client runtime config resolve correctly under /ks); the failure is isolated to import() chunk URLs.

Expected: dynamically-imported chunk URLs honour ROOT_URL_PATH_PREFIX in production, exactly as the main bundle does.

Relationship to #14716

Same family as #14716 (Rspack not honouring ROOT_URL_PATH_PREFIX) but a distinct defect:

  • #14716 is about the Rspack dev client script being injected without the prefix (development).
  • This report is about the production chunk-loader publicPath omitting the prefix for import() chunks.

A fix for one does not necessarily cover the other, since they are different code paths (dev script injection vs. prod chunk publicPath).