Skip to content

Conversation

Copy link

Copilot AI commented Jan 17, 2026

  • Analyze the bug: Module grouping exception when a module is both an entry file and dynamically imported
  • Identify root cause: In module_group_graph_from_entries, edges are created with ModuleGroupType::DynamicImport for dynamically imported modules, but if that module is also an entry, its module group ID uses ModuleGroupType::Entry instead
  • Implement fix: Check if dynamic import target is an entry, and if so, use Entry type for edge target
  • Add test case to reproduce and validate the fix
  • Run existing tests to ensure no regressions (all 17 partial bundling tests pass)
  • Remove unnecessary comments per reviewer feedback
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug Report]: When a module serves as both an entry file and dynamically introduces dependencies, it can cause module grouping exceptions</issue_title>
<issue_description>### Steps to reproduce

  1. Project Structure

    examples/import-meta/
    ├── a.ts
    ├── index.ts
    ├── farm.config.ts
    └── package.json
    
  2. index.ts

    console.log(new URL("./foo.txt", import.meta.url));
    
    function loadA() {
      import("./a").then((res) => {
        console.log("res:", res);
      });
    }
  3. a.ts

    export const msg = "hello from a";
  4. farm.config.ts
    (Make sure to explicitly set both index.ts and a.ts as entries.)

    export default {
      input: {
        main: "./index.ts",
        a: "./a.ts",
      },
    };
  5. Run the Build

Reproduce link

No response

What is actually happening?

Expected to optimize the entry type, but an error occurred:

thread '<unnamed>' panicked at crates/core/src/module/module_group.rs:47:51:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Rayon: detected unexpected panic; aborting

System Info

System:
    OS: macOS 26.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 78.56 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.17.1 - /Users/ming07/.nvm/versions/node/v22.17.1/bin/node
    Yarn: 1.22.5 - /Users/ming07/.yarn/bin/yarn
    npm: 10.9.2 - /Users/ming07/.nvm/versions/node/v22.17.1/bin/npm
    pnpm: 9.12.2 - /Users/ming07/Library/pnpm/pnpm
    Deno: 1.23.2 - /Users/ming07/.deno/bin/deno
    Watchman: 2023.04.10.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 143.0.7499.41
    Safari: 26.1
  npmPackages:
    @farmfe/core: workspace:* => 2.0.0-beta.7
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@changeset-bot
Copy link

changeset-bot bot commented Jan 17, 2026

⚠️ No Changeset found

Latest commit: 41112a6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

💥 An error occurred when fetching the changed packages and changesets in this PR
Some errors occurred when validating the changesets config:
The package or glob expression "farm-docs" is specified in the `ignore` option but it is not found in the project. You may have misspelled the package name or provided an invalid glob expression. Note that glob expressions must be defined according to https://www.npmjs.com/package/micromatch.
The package or glob expression "bench" is specified in the `ignore` option but it is not found in the project. You may have misspelled the package name or provided an invalid glob expression. Note that glob expressions must be defined according to https://www.npmjs.com/package/micromatch.

@coderabbitai
Copy link

coderabbitai bot commented Jan 17, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel
Copy link

vercel bot commented Jan 17, 2026

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

Project Deployment Review Updated (UTC)
farm-docs Ready Ready Preview, Comment Jan 17, 2026 2:07pm

…mport

Co-authored-by: Nirvana-Jie <72637162+Nirvana-Jie@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix module grouping exceptions for entry files and dynamic dependencies Fix module grouping panic when entry is also dynamically imported Jan 17, 2026
Copilot AI requested a review from Nirvana-Jie January 17, 2026 12:30
@Nirvana-Jie
Copy link
Contributor

@copilot Delete useless comment

Co-authored-by: Nirvana-Jie <72637162+Nirvana-Jie@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 17, 2026

@copilot Delete useless comment

Done in 41112a6.

@Nirvana-Jie Nirvana-Jie changed the title Fix module grouping panic when entry is also dynamically imported Fix: module grouping panic when entry is also dynamically imported Jan 17, 2026
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.

[Bug Report]: When a module serves as both an entry file and dynamically introduces dependencies, it can cause module grouping exceptions

2 participants