Skip to content

fix: fix chunk assignment for deoptimized module with dynamic import#6306

Merged
lukastaegert merged 2 commits intorollup:masterfrom
JoaoBrlt:fix_issue_6305
Mar 20, 2026
Merged

fix: fix chunk assignment for deoptimized module with dynamic import#6306
lukastaegert merged 2 commits intorollup:masterfrom
JoaoBrlt:fix_issue_6305

Conversation

@JoaoBrlt
Copy link
Contributor

@JoaoBrlt JoaoBrlt commented Mar 19, 2026

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

List any relevant issue numbers:

Description

Minimal reproducible example

https://github.com/JoaoBrlt/rollup-dynamic-import-bug

Problem

The getDynamicallyDependentEntriesByDynamicEntry() function assumed that every module in the includedDynamicImporters list was also present in the dependentEntriesByModule map. That assumption could be violated when a module was marked as executed via the de-optimization path (using the markModuleAndImpureDependenciesAsExecuted() function) rather than the normal static-dependency traversal.

Proposed solution

Skip any importer that is not present in dependentEntriesByModule instead of asserting its presence with !.

Test

Added test/chunking-form/samples/deoptimized-module-with-dynamic-import/ reproducing the issue. The test fails on the unfixed code with TypeError: dependentEntriesByModule.get is not a function or its return value is not iterable and passes after the fix. I designed the test to reproduce more or less the situation that I faced in my current project and in the minimal reproducible example.

@vercel
Copy link

vercel bot commented Mar 19, 2026

@JoaoBrlt is attempting to deploy a commit to the rollup-js Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rollup Error Error Mar 20, 2026 4:58pm

Request Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in Rollup’s chunk-assignment analysis when a dynamically importing module is present in a dynamic entry’s importer list but is absent from dependentEntriesByModule (e.g. when execution is triggered via the de-optimization path), addressing #6305.

Changes:

  • Make getDynamicallyDependentEntriesByDynamicEntry() tolerate missing dependentEntriesByModule entries by skipping those importers.
  • Add a new chunking-form regression sample covering the deoptimized + dynamic import scenario.
  • Add expected outputs for the new sample across es, cjs, amd, and system formats.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/utils/chunkAssignment.ts Avoids iterating undefined by skipping importers not present in dependentEntriesByModule.
test/chunking-form/samples/deoptimized-module-with-dynamic-import/_config.js Adds a chunking-form test config that reproduces the deoptimization-path scenario.
test/chunking-form/samples/deoptimized-module-with-dynamic-import/main.js Test entry for the new regression sample.
test/chunking-form/samples/deoptimized-module-with-dynamic-import/a.js Sample module that sets up the conditions (including a dynamic import) relevant to the bug.
test/chunking-form/samples/deoptimized-module-with-dynamic-import/lazy-loader.js Sample module used to trigger the problematic importer state.
test/chunking-form/samples/deoptimized-module-with-dynamic-import/cjs.js Dynamically imported module used by the regression sample.
test/chunking-form/samples/deoptimized-module-with-dynamic-import/_expected/es/main.js Expected ES output for the new regression sample.
test/chunking-form/samples/deoptimized-module-with-dynamic-import/_expected/cjs/main.js Expected CJS output for the new regression sample.
test/chunking-form/samples/deoptimized-module-with-dynamic-import/_expected/amd/main.js Expected AMD output for the new regression sample.
test/chunking-form/samples/deoptimized-module-with-dynamic-import/_expected/system/main.js Expected System output for the new regression sample.

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.77%. Comparing base (d46200f) to head (7810bfa).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6306   +/-   ##
=======================================
  Coverage   98.77%   98.77%           
=======================================
  Files         273      273           
  Lines       10725    10728    +3     
  Branches     2859     2860    +1     
=======================================
+ Hits        10594    10597    +3     
  Misses         89       89           
  Partials       42       42           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Thanks a lot! This is really a tricky bug, and I spent quite some time contemplating if there is a deeper problem, but I convinced myself that your fix is essentially correct and it should not be possible to trigger actual broken states here.
Great work on the reproduction and analysis! Will release this once the pipeline agrees.

@lukastaegert lukastaegert enabled auto-merge March 20, 2026 16:57
@lukastaegert lukastaegert added this pull request to the merge queue Mar 20, 2026
Merged via the queue into rollup:master with commit 1cd49ae Mar 20, 2026
46 of 47 checks passed
@JoaoBrlt
Copy link
Contributor Author

Hey! 👋 Thanks a lot for reviewing and merging the PR so quickly. Really appreciate you taking the time! ☺️

@github-actions
Copy link

This PR has been released as part of [email protected]. You can test it via npm install rollup.

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.

TypeError: dependentEntriesByModule.get is not a function during chunk generation (dynamic imports)

3 participants