Skip to content

TURBOPACK: fix subpath imports resolving to dependencies#93914

Open
yuzheng14 wants to merge 1 commit into
vercel:canaryfrom
utooland:fix-turbopack-subpath-imports-dependencies
Open

TURBOPACK: fix subpath imports resolving to dependencies#93914
yuzheng14 wants to merge 1 commit into
vercel:canaryfrom
utooland:fix-turbopack-subpath-imports-dependencies

Conversation

@yuzheng14
Copy link
Copy Markdown

Summary

  • Fix Turbopack's package.json#imports handling so subpath imports can resolve to bare package specifiers.
  • Preserve the existing relative-path behavior for exports and relative subpath import targets.
  • Add a snapshot fixture for a subpath import that resolves to a dependency from node_modules.

Previously, the existing #dep case could appear to work because Turbopack always prepended ./ to the resolved target. That turned "dep" into "./dep", and the fixture happened to contain a matching local ./dep directory. This did not cover the valid subpath imports case where the target should be resolved as an external package dependency.

Test plan

  • Commit hook ran lint-staged, including rustfmt, Prettier, and ESLint for the staged files.
  • Updated the subpath-imports snapshot fixture and output.

Made with Cursor

Allow package.json subpath imports targets to resolve as bare package specifiers instead of always forcing relative paths. Add a snapshot fixture that verifies an imports entry can point to a dependency in node_modules.
Comment on lines 3285 to 3286
// Remove the Pattern::Constant(rcstr!("./")), from above again
old_request_key.push_front(rcstr!("./").into());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the non-./-appended pattern above matched, then this would be wrong.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If the non-./-appended pattern above matched, then this would be wrong.

This branch won't be reached when resolving Imports fields, because we're using Pattern::Constant. In that case, req.as_constant_string() will alwyas return Some, so the branch condition never matches.

daltino

This comment was marked as spam.

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