Skip to content

CJS external facade doesn't account for the default export being a function #20047

Description

@jamesopstad

Describe the bug

Some modules, such as node:stream export a function as the default export. When imported in an optimized dependency with the CJS external facade, require_stream should return a function with the named exports as its enumerable properties. This is the source of the error reported here - cloudflare/workers-sdk#9225.

Reproduction

https://github.com/alexanderniebuhr/cf-vite-jsonwebtoken

Steps to reproduce

Run pnpm i followed by pnpm dev.

System Info

System:
    OS: macOS 15.4.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 470.09 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.5.1 - ~/.nvm/versions/node/v22.5.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v22.5.1/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v22.5.1/bin/npm
    pnpm: 10.7.0 - ~/.nvm/versions/node/v22.5.1/bin/pnpm
  Browsers:
    Chrome: 136.0.7103.93
    Safari: 18.4

Used Package Manager

pnpm

Logs

TypeError: The "superCtor.prototype" property must be of type object. Received undefined

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions