Skip to content

[Bug]: Bundling serve-static into ESM output breaks require("stream") interop #1535

@chenjiahan

Description

@chenjiahan

Version

- `@rslib/core`: `0.20.0`

Details

Bundling serve-static into ESM output breaks require("stream") interop:

[rspack-cli] Failed to load "@rspack/dev-server":
The "superCtor.prototype" property must be of type object. Received undefined

serve-static pulls in send, which does:

var Stream = require("stream");
util.inherits(SendStream, Stream);

In the generated ESM bundle, Node builtins appear to be externalized via:

import * as __rspack_external_stream from "stream";

and that value is then returned for require("stream").

So bundled CommonJS code receives the ESM namespace object instead of the native CJS stream export, and util.inherits fails because Stream.prototype is undefined.

Expected

Either:

  • bundled CommonJS dependencies should preserve require("stream") semantics in ESM output, or
  • the build should warn/error if this case is unsupported.

Actual

The build succeeds, but the runtime crashes during module initialization.

Reproduce link

rstackjs/rspack-dev-server#163

Reproduce Steps

pnpm install
pnpm build
pnpm --dir example dev

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions