Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/vinext/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,16 @@ hydrate();
}
}

// Handle directory imports without extension (e.g., "next/font/local")
// Libraries like geist import "next/font/local" as a directory which
// Vite's ESM resolution rejects. Resolve through our shim map.
if (cleanId.startsWith("next/") && !cleanId.endsWith(".js")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The condition cleanId.startsWith("next/") && !cleanId.endsWith(".js") matches every non-.js next/* import — not just "directory imports". For example, "next/navigation", "next/link", and "next/router" all match this condition.

This is benign (the shim map has those entries and the alias would resolve them anyway), but the comment "Handle directory imports without extension" is misleading — it implies only directory-like paths are caught, when in reality all next/* bare imports match.

Consider either:

  1. Making the comment accurate: "Fallback for any next/* bare import not resolved by resolve.alias"
  2. Or narrowing the condition if you truly only want directory-style subpath imports (e.g., paths with more than one / segment after next/)

if (nextShimMap[cleanId]) {
const shimPath = nextShimMap[cleanId];
return shimPath.endsWith(".js") ? shimPath : shimPath + ".js";
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic is identical to what the .js handler above does (lines 2101-2103). Rather than duplicating, consider merging both blocks into a single handler as suggested in the review summary. This reduces code duplication and makes the intent clearer.

}
}

// Pages Router virtual modules
if (cleanId === VIRTUAL_SERVER_ENTRY) return RESOLVED_SERVER_ENTRY;
if (cleanId === VIRTUAL_CLIENT_ENTRY) return RESOLVED_CLIENT_ENTRY;
Expand Down