Skip to content

fix(pack): disable ts_transform for foreign_code#2267

Merged
xusd320 merged 3 commits intonextfrom
fix-resolve-foreign-tsconfig
Oct 27, 2025
Merged

fix(pack): disable ts_transform for foreign_code#2267
xusd320 merged 3 commits intonextfrom
fix-resolve-foreign-tsconfig

Conversation

@fireairforce
Copy link
Contributor

@fireairforce fireairforce commented Oct 27, 2025

Summary

PR: #2237 为了处理 node_modules 中的 alias 给 foreign_code 开启了 enable_typescript 配置,turbopack 在开启这个配置后处理 node_modules 中的依赖时会去解析对应的 tsconfig.json 文件(做 typescript transform  用),但实际上很多 npm 包 tsconfig file 中的依赖是 devDependencies,这会导致 resolve errror,参考:

截屏2025-10-27 17 16 25

之前 alias 这个问题的时候,本质上还是从 extensions 的角度来处理,这里默认给 foreign_code 的 extensions 打开更多的后缀即可。

Test Plan

旧的快照测试不变,新增了 node_modules/tsconfig-mod/tsconfig.json 相关的测试 case.

@gemini-code-assist
Copy link
Contributor

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!

This pull request addresses a critical build failure in Turbopack where enabling TypeScript transformation for external modules (e.g., node_modules) inadvertently caused resolution errors due to the parsing of tsconfig.json files within those packages. The solution involves a refined module resolution strategy that explicitly defines allowed file extensions for foreign code, effectively preventing Turbopack from attempting to process tsconfig.json files in third-party dependencies and ensuring a more stable build process.

Highlights

  • Resolving tsconfig.json issues in node_modules: Previously, enabling TypeScript transformation for foreign_code (like node_modules) caused Turbopack to attempt parsing tsconfig.json files within npm packages. This often led to resolution errors because these tsconfig.json files might reference devDependencies or have configurations not intended for runtime resolution.
  • Disabling ts_transform for foreign_code: The core fix involves explicitly defining custom_extensions for foreign_code resolution, rather than relying on enable_typescript to implicitly handle tsconfig.json parsing. This ensures that node_modules are resolved based on their file extensions, bypassing potentially problematic tsconfig.json configurations.
  • Refined module resolution strategy: The change refactors the ResolveOptionsContext to separate default options from foreign_code specific options, allowing for more precise control over how external modules are processed without causing unintended side effects.
  • Enhanced test coverage: New snapshot test cases have been added, specifically targeting scenarios involving node_modules with tsconfig.json files that previously caused errors, ensuring the fix is robust and prevents regressions.
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
Contributor

@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

这个 PR 的目标是修复在处理 node_modules 中的依赖时,因解析其中的 tsconfig.json 文件而导致的 resolve error。通过为 foreign_code(即 node_modules 中的代码)禁用 enable_typescript 选项,并手动提供文件扩展名列表,这个修改有效地解决了问题。新增的测试用例也很好地覆盖了修复的场景。整体来看,这是一个不错的修复。我有一个关于代码可维护性的建议。

@xusd320 xusd320 merged commit 35b33f8 into next Oct 27, 2025
17 checks passed
@xusd320 xusd320 deleted the fix-resolve-foreign-tsconfig branch October 27, 2025 10:30
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