@meteorjs/rspack: missing externalsType produces invalid JS under @rspack/core 2.0.0
Bug
Under @rspack/core 2.0.0 + @meteorjs/rspack 1.0.2 (also reproduces on 1.1.0-beta.37), compileWithMeteor() externals are emitted as raw bareword identifiers in the generated bundle, which is invalid JavaScript:
// .meteor/local/build/programs/server/app/app.js
"@bull-board/api"(module) {
"use strict";
module.exports = @bull-board/api; // ← raw identifier, SyntaxError
},
"geoip-country"(module) {
"use strict";
module.exports = geoip-country; // ← treated as subtraction
},
"meteor/accounts-base"(module) {
"use strict";
module.exports = meteor/accounts-base;
}
Server boot fails with:
SyntaxError: Invalid or unexpected token
at new Script (node:vm:117:7)
at startServerProcess (.../tools/static-assets/server/boot.js:501:17)
Production meteor build exhibits the same problem on the client side for meteor/* externals during minification, e.g.:
const tracker_namespaceObject = meteor/tracker;
const a4xrbj1_streamy_namespaceObject = meteor/a4xrbj1:streamy;
→ JavaScript parse error: Expected a semicolon from the SWC minifier.
Root cause
@meteorjs/rspack/rspack.config.js sets externals: [...] and externalsPresets: { node: true } but never sets externalsType. Under @rspack/core 1.x, the implicit default for these targets emitted module.exports = require("name") (commonjs). Under @rspack/core 2.0.0, the default appears to emit a bare-word form (module.exports = name; / const X = name;), which is only valid when the external name is a syntactically valid JS identifier. Scoped names (@bull-board/api), names with hyphens (geoip-country), and Meteor-style names with / and : (meteor/a4xrbj1:streamy) all break.
Reproduction
- Meteor 3.4 app with
@meteorjs/rspack ^1.0.2,@rspack/cli ^2.0.0,@rspack/core ^2.0.0,@rspack/dev-server ^2.0.1. - In
rspack.config.js:const { defineConfig } = require('@meteorjs/rspack'); module.exports = defineConfig((Meteor) => ({ ...(Meteor.isServer && Meteor.compileWithMeteor(['@bull-board/api', 'geoip-country'])), })); - `meteor run` → server boot crashes with
SyntaxError: Invalid or unexpected tokenon first invalid identifier.
Workaround (verified)
Add `externalsType: 'commonjs'` to both `Meteor.isServer` and `Meteor.isClient` blocks of the user's `rspack.config.js`:
```js module.exports = defineConfig((Meteor) => ({ ...(Meteor.isServer && Meteor.compileWithMeteor([...])), ...(Meteor.isServer && { externalsType: 'commonjs', }), ...(Meteor.isClient && { externalsType: 'commonjs', }), })); ```
Verified: dev boot clean, prod `meteor build` clean (server bundle 6.7 MB, client bundle 1.9 MB, all externals correctly emit `module.exports = require("…")`).
Proposed fix
Add `externalsType: 'commonjs'` to the base config in `@meteorjs/rspack/rspack.config.js` (alongside the existing `externalsPresets: { node: true }` declaration around line 779), inside whatever target merge produces server bundles, and a matching one for client bundles. This restores the rspack 1.x emission semantics and is forward-compatible with rspack 2.x.
Environment
- `@rspack/core` 2.0.0 (released 2026-04-22)
- `@rspack/cli` 2.0.0
- `@rspack/dev-server` 2.0.1
- `@meteorjs/rspack` 1.0.2 (also reproduces on 1.1.0-beta.37)
- Meteor 3.4
- Node 22.22.0
- macOS arm64
Source: meteor/meteor