Vite — Resolve `import.meta.glob` in TypeScript

Vite is a modern tool to bundle your frontend assets. You’re mainly using ES Modules when working with Vite. And Vite extends the global import.meta object with handy utilities. For example, it adds an import.meta.glob function allowing you to resolve files from a path.

In combination with TypeScript, you may have issues that it doesn’t pick up Vite’s type declarations. Without Vite’s type declarations, you’re running into compiler issues.

Read on to resolve Vite’s types and tell TypeScript about the provided import.meta utilities.

Vite Series Overview

Resolve Vite’s import.meta.glob in TypeScript

Vite ships with TypeScript types and your editor or IDE should automatically resolve the types. If you’re still running into typing issues, you may explicitly add the vite/client to the types array inside your tsconfig.json file.

tsconfig.json

{
  "compilerOptions": {
    "types": ["vite/client"] // 👈 add this
  }
}

Adding vite/client to the types array fixed the typing issue for us in Visual Studio Code.

Sweet!

Explore the Library

Find interesting tutorials and solutions for your problems.