Open
Description
Describe the bug
Current Behavior
// Type: Record<string, () => Promise<unknown>>
const modules = import.meta.glob('*.ts');
// This doesn't trigger TypeScript errors, but can cause runtime issues
const loader = modules['nonexistent-file.ts']; // Type: () => Promise<unknown>
await loader(); // Runtime error: loader is undefined
Expected Behavior
// Type: Partial<Record<string, () => Promise<unknown>>>
const modules = import.meta.glob('*.ts');
// TypeScript should enforce safe access
// Type: (() => Promise<unknown>) | undefined
const loader = modules['nonexistent-file.ts'];
const safeLoader = modules?.['some-file.ts'];
Reproduction
Steps to reproduce
No response
System Info
System:
OS: Windows 11 10.0.26100
CPU: (8) x64 Intel(R) Core(TM) Ultra 7 258V
Memory: 4.38 GB / 31.51 GB
Binaries:
Node: 24.1.0 - ~\AppData\Local\fnm_multishells\32740_1748604076193\node.EXE
npm: 11.3.0 - ~\AppData\Local\fnm_multishells\32740_1748604076193\npm.CMD
pnpm: 10.11.0 - ~\AppData\Local\fnm_multishells\32740_1748604076193\pnpm.CMD
Browsers:
Edge: Chromium (131.0.2903.112)
npmPackages:
vite: ^6.3.5 => 6.3.5
Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.