Skip to content

Conversation

@fireairforce
Copy link

@fireairforce fireairforce commented Dec 15, 2025

主要为了修复: utooland/utoo#2385

有个循环依赖的例子:

// a.ts
import c from './c';

export default c;
// c.ts
import a from './a';

a;

const c = 1;
export default c;

在 codegen 的时候 turbopack 会把 a module 里面的 c module 的导出给提上来,看上去是为了避免 import 消费的模块能找到对应的变量。

image

参考代码逻辑: https://github.com/utooland/next.js/blob/utoo/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs#L825

于是就会构造出 issue 中的报错,这里简单的解决办法就是把 const 替换成 var,让变量同样提升上去。

本地测试正常。

@gemini-code-assist
Copy link

Summary of Changes

Hello @fireairforce, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求解决了 Turbopack 在 ESM 导出代码生成中,当存在循环依赖时遇到的特定问题。通过将默认导出变量的声明从 const 切换到 var,确保了这些变量能够正确地被提升,从而解决了在相互依赖的模块中过早访问导致的运行时错误。这一改变提升了 Turbopack 在复杂依赖场景下模块打包的健壮性。

Highlights

  • 修复循环依赖问题: 解决了 Turbopack 在 ESM 导出代码生成中处理循环依赖时,由于使用 const 声明导致变量无法提升的问题。
  • 更改代码生成逻辑: 将默认导出的变量声明从 const 更改为 var,以确保在存在循环依赖的情况下,变量能够正确提升。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

你好,感谢你的贡献。这个 Pull Request 通过将 ESM 导出代码生成中的 const 替换为 var,旨在解决循环依赖问题。这个改动是正确且有效的。通过使用 var,利用其变量提升的特性,可以避免在循环依赖场景中因“暂时性死区”(Temporal Dead Zone)而导致的 ReferenceError。这是一个处理此类问题的标准做法。我对 turbopack/crates/turbopack-ecmascript/src/references/esm/module_item.rsturbopack/crates/turbopack-ecmascript/src/tree_shake/graph.rs 中的改动进行了审查,确认它们都符合预期,并且共同解决了所描述的问题。整体来看,这是一个高质量的修复,代码清晰,目标明确。我没有发现任何问题。

@fireairforce fireairforce merged commit bb44131 into utoo Dec 16, 2025
13 of 26 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.

3 participants