Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
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.

1 participant