Turbopack: accept a module type argument for import.meta.glob - #96991
Open
kelvinampofo wants to merge 2 commits into
Open
Turbopack: accept a module type argument for import.meta.glob#96991kelvinampofo wants to merge 2 commits into
kelvinampofo wants to merge 2 commits into
Conversation
kelvinampofo
marked this pull request as draft
August 9, 2026 18:04
Vite's types take a module type argument, Next's do not, so there is no way to describe what the matched files export and each call site needs a cast. Defaulting to unknown leaves existing calls resolving as they do today.
kelvinampofo
force-pushed
the
import-meta-glob-generic
branch
from
August 9, 2026 18:38
60deda6 to
2eb6e29
Compare
kelvinampofo
commented
Aug 9, 2026
kelvinampofo
marked this pull request as ready for review
August 9, 2026 18:56
The fixture declared its own ImportMeta.glob returning Record<string, any>, which shadowed the shipped declarations, so the test never exercised them. It was added in vercel#92640, before those declarations existed. Typing the globs makes next build fail without the module generic.
kelvinampofo
force-pushed
the
import-meta-glob-generic
branch
from
August 9, 2026 19:04
2eb6e29 to
c350726
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Adds support for passing a module type to the TypeScript overloads for
import.meta.glob:This works with both lazy and eager imports. If a module type isn’t provided, it defaults to
unknown, which matches the current behavior.Why?
Next.js already supports Vite’s
import.meta.globAPI at runtime, but its TypeScript declarations don’t support Vite’s module generic.Because of this, a typed glob works in Vite but fails in Next.js:
Consumers currently have to cast the result or add their own
ImportMetadeclaration to describe the matched modules. Supporting the generic removes the need for those workarounds and makes typed glob imports consistent between Next.js and Vite.How?
Each existing overload now accepts a generic module type,
M, which defaults tounknown:Record<string, () => Promise<M>>.Record<string, M>.Using
unknownas the default means existing calls without a generic keep the same types as before.I also updated the existing e2e fixture. It had an old local
ImportMeta.globdeclaration that returnedRecord<string, any>. Removing that declaration exposed the missing generic and allowed the fiveas anycasts in the fixture to be removed. Without the generic, all five glob calls fail duringnext buildwithTS2558. With it, all five pass.The Turbopack documentation has also been updated with examples showing how to use the generic with lazy and eager imports.
Checklist
pnpm --filter=next typespassespnpm prettier-fixrun