ProjectStack
typescript

TS1343: The 'import.meta' meta-property is only allowed when '--module' is set to a valid module option

You're using import.meta (common in Vite and ESM projects) but TypeScript isn't configured to compile for a module format that supports it. The module option in tsconfig.json needs to be set to esnext, es2020, node16, or another ESM-compatible format.

Common causes

  • The tsconfig.json module option is set to commonjs or another non-ESM format
  • No module option is set in tsconfig.json, defaulting to a format that doesn't support import.meta
  • Using import.meta.env (Vite) or import.meta.url in a CommonJS-configured project
  • Migrating from CommonJS to ESM without updating tsconfig.json

How to fix it

  1. Set module to esnext in tsconfig.json: { "compilerOptions": { "module": "esnext" } }
  2. For Node.js projects targeting Node 16+: "module": "node16" or "nodenext"
  3. For Vite projects: "module": "esnext", "moduleResolution": "bundler"
  4. Add vite/client types if using Vite-specific globals: { "types": ["vite/client"] }

Example

const apiUrl = import.meta.env.VITE_API_URL; // error TS1343: The 'import.meta' meta-property is only allowed when '--module' is set to 'es2020', 'esnext', 'node16', or 'nodenext'.

Using Vite's import.meta.env with a tsconfig still set to commonjs module format

Browse more errors

The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.