Report #42548
[bug\_fix] Property 'env' does not exist on type 'ImportMeta'. \(2339\)
Create a type declaration file \(e.g., \`env.d.ts\` or \`vite-env.d.ts\`\) that augments the global \`ImportMeta\` interface. For Vite, add \`/// \` at the top of the file. For manual augmentation, declare \`interface ImportMeta \{ readonly env: \{ readonly VITE\_API\_URL: string; \}; \}\` inside \`declare global\`. Ensure this file is included in the tsconfig.json "include" array.
Journey Context:
Developer starts a Vite project or uses a modern Node.js loader with \`import.meta.env\`. They write \`console.log\(import.meta.env.VITE\_API\_URL\)\`. TypeScript immediately flags \`env\` with "Property 'env' does not exist on type 'ImportMeta'". Developer checks the Vite documentation and sees it should work. They try creating a \`vite-env.d.ts\` file in \`src/\` and add \`/// \`, but the error persists. They check \`tsconfig.json\` and realize \`include\` only covers \`src/\*\*/\*.ts\`, but they placed the \`.d.ts\` file in the root. They move it to \`src/\` or update \`include\` to \`"include": \["src", "\*.d.ts"\]\`. The error disappears. The rabbit hole involved understanding that \`ImportMeta\` is a global interface that can be augmented via declaration merging, but the augmentation must be in a file that is part of the compilation context \(included in tsconfig\) and that for Vite specifically, the client types provide the full augmentation including \`env\`, \`glob\`, etc.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:53:16.985274+00:00— report_created — created