Skip to content

Conversation

@craftingmod
Copy link

@craftingmod craftingmod commented Jan 27, 2026

What does this PR do?

Fixes package name resolution in subpath imports on Windows by using POSIX path separators (/) instead of Windows separators (\).

Related issues

#26069

What is the issue?

On Windows, when resolving subpath imports that redirect to scoped packages (e.g., #resolver@myproject/resolver), the resolver incorrectly uses backslashes (\) as path separators, converting @myproject/resolver to @myproject\resolver.
This causes:

  • Package name not recognized
  • exports field ignored
  • Wrong module type resolved (CJS instead of ESM)

Package names must always use forward slashes per Node.js specification, regardless of platform.

How did you verify your code works?

  1. Clone subpath import test project
git clone https://github.com/craftingmod/bun-subpath-import-slash.git
cd bun-subpath-import-slash
bun install
  1. Run test
bun run test:bun
  1. Check output
 4 pass
 0 fail
 4 expect() calls
Ran 4 tests across 1 file. [218.00ms]

Platform

  • Windows
  • macOS
  • Linux

This fix only affects Windows builds. Other platforms already use POSIX separators.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

Walkthrough

Path separator handling updated in ESModule.resolveTarget function from automatic to POSIX separators when resolving string targets without patterns. An explanatory comment referencing Node.js specifications is included. This change affects resolved path results on systems with different path separators, particularly Windows.

Changes

Cohort / File(s) Change Summary
Path separator behavior
src/resolver/package_json.zig
Modified package URL joining logic in ESModule.resolveTarget to use POSIX separators instead of automatic separators for string target resolution. Added clarifying comment about Node.js specification requirement. Affects subpath resolution outcomes on non-POSIX systems.

Suggested reviewers

  • nektro
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: using POSIX separators for package name resolution on Windows, which directly matches the core change in the PR.
Description check ✅ Passed The description fully addresses both required template sections with comprehensive context: explains what the PR does, details the Windows-specific issue with backslashes in package names, and provides clear verification steps with expected output.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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.

1 participant