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
- Set module to esnext in tsconfig.json: { "compilerOptions": { "module": "esnext" } }
- For Node.js projects targeting Node 16+: "module": "node16" or "nodenext"
- For Vite projects: "module": "esnext", "moduleResolution": "bundler"
- 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.
