Skip to content

fix(commonjs): fix crash with invalidated proxy modules#1876

Merged
shellscape merged 1 commit intomasterfrom
fix/commonjs/handle-invalidated-proxy-modules
Jun 17, 2025
Merged

fix(commonjs): fix crash with invalidated proxy modules#1876
shellscape merged 1 commit intomasterfrom
fix/commonjs/handle-invalidated-proxy-modules

Conversation

@lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented Jun 14, 2025

In watch mode when the code imports CommonJS from ESM, depending on the setup, it can happen that the ES to Commonjs proxy module is re-evaluated. If that happens, its meta information is lost, leading to a weird crash.

Rollup Plugin Name: commonjs

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Description

I stumbled upon a case where in watch mode when changing a file, the CommonJS plugin would show a weird error. What happened is that a proxy module that was generated for a CommonJS from ESM import was being re-evaluated in its importer's shouldTransformCachedModule hook. Due to a small bug, the meta information of the proxy was lost, leading to a crash. This fixes it by supplying this meta information via loading the full resolved id object (that contains the meta information) instead of just using the id.

In watch mode when the code imports CommonJS from ESM, depending on the setup,
it can happen that the ES to Commonjs proxy module is re-evaluated. If that
happens, its meta information is lost, leading to a weird crash.
@lukastaegert lukastaegert requested a review from shellscape as a code owner June 14, 2025 06:19
@shellscape shellscape merged commit 7b9d40d into master Jun 17, 2025
10 checks passed
@shellscape shellscape deleted the fix/commonjs/handle-invalidated-proxy-modules branch June 17, 2025 13:21
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