Skip to content

fix(compiler): _interopNamespace not defined in cjs#6272

Merged
christian-bromann merged 1 commit intostenciljs:mainfrom
igorwessel:fix/cjs-build-when-enableimportinjection
Jun 3, 2025
Merged

fix(compiler): _interopNamespace not defined in cjs#6272
christian-bromann merged 1 commit intostenciljs:mainfrom
igorwessel:fix/cjs-build-when-enableimportinjection

Conversation

@igorwessel
Copy link
Copy Markdown
Contributor

@igorwessel igorwessel commented May 31, 2025

What is the current behavior?

When set enableImportInjection, this code uses _interopNamespace rollup helper

const generateCaseClauseCjs = (bundleId: string): string => {
return `
case '${bundleId}':
return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(
/* webpackMode: "lazy" */
'./${bundleId}.entry.js')); }).then(processMod, consoleError);`;
};

After Rollup upgrade currently CJS build with this flag enabled, don't have the rollup helper.

GitHub Issue Number: #6270

What is the new behavior?

Basically we are making sure that it is generating the _interopNamespace when the enableImportInjection setting is being used.

Documentation

Rollup Interop
Rollup Dynamic Import is the new default

Does this introduce a breaking change?

  • Yes
  • No

Testing

Generate a dev stencil build, link with npm link, and test inside the issue repo.
Check the index.js that loader.cjs uses

Other information

…ction is enabled

When config.extras.enableImportInjection (or experimentalImportInjection) is enabled, set Rollup's interop: 'auto' and dynamicImportInCjs: false in the CJS output options. This ensures that Rollup generates the _interopNamespace helper for proper ESM/CJS interoperability.
@igorwessel igorwessel requested a review from a team as a code owner May 31, 2025 22:00
@igorwessel igorwessel changed the title fix(compiler): disable dynamic imports in cjs when pass enableImportI… fix(compiler): _interopNamespace not defined in cjs Jun 1, 2025
Copy link
Copy Markdown
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks a lot!

@christian-bromann christian-bromann merged commit 58d4ad0 into stenciljs:main Jun 3, 2025
143 of 144 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants