Skip to content

bug: v5 loader-bundle with cjs: true calls _interopNamespace, which is not defined #7040

Done

Description

@henrijoss

Stencil Version

5.0.0-rc.9

Current Behavior

No component of the CommonJS build of a loader-bundle output target (cjs: true) can be loaded. Loading the first one throws:

ReferenceError: _interopNamespace is not defined
    at …/dist/loader-bundle/cjs/runtime-Cvx3TWGo.js:299:65
Error: Constructor for "repro-cjs#undefined" was not found

The runtime chunk calls the helper once per component and defines it nowhere:

case 'repro-cjs.cjs':
    return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(
        /* webpackMode: "lazy" */
        './repro-cjs.cjs.entry.js')); }).then(onLoad, onError);

Expected Behavior

The CommonJS build loads its components, e.g. in Node with jsdom for unit tests.

4.45.1 does, with a dist output target and extras.enableImportInjection: its CommonJS core chunk defines _interopNamespace, and the same component renders.

System Info

      System: node 22.21.0
    Platform: darwin (27.0.0)
   CPU Model: Apple M2 Pro (12 cpus)
     Stencil: 5.0.0-rc.9 🏐
  TypeScript: 6.0.3
    Rolldown: 1.3.3
      Terser: 5.51.4

DOM: jsdom 27.4.0

Steps to Reproduce

  1. Clone https://github.com/henrijoss/stencil-v5-repros and run npm install
  2. npm run repro --workspace=cjs-interop

It builds the project and requires dist/loader-bundle/loader/index.cjs in Node with jsdom. Expected output is shadow root content: "<p>rendered</p>", actual output is the error above and an empty shadow root.

Code Reproduction URL

https://github.com/henrijoss/stencil-v5-repros/tree/main/cjs-interop

Additional Information

generateCaseClauseCjs() in packages/core/src/compiler/output-targets/dist-lazy/generate-lazy-module.ts writes _interopNamespace(require(…)) as text. That is a helper Rollup added to CommonJS output; the Rolldown output doesn't contain it. Import injection is on by default in v5 (compat.enableImportInjection), so every cjs: true build is affected.

Workaround: compat: { enableImportInjection: false }. The component in the reproduction renders with it.

The code is the same in 5.0.0-rc.10; I only ran rc.9 (and first saw this with rc.1).

The same error was reported in #6270 and fixed in #6272.

Activity

  1. johnjenkins commented on Nov 25, 2026

    @johnjenkins
    Contributor

    TYSM for trying out v5. This was fixed in 5.0.0-rc.11 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions