Property 'env' does not exist on type 'ImportMeta' in 3.0.0
See original GitHub issueDescribe the bug
In vite 3.0.0 it still exists, even if it was previously closed.
Can be recreated using react-ts template. Try to use env variable via import.meta.env, TS will give you an error Property 'env' does not exist on type 'ImportMeta'.
According to the docs it should work: https://vitejs.dev/guide/env-and-mode.html
Reproduction
yarn create vite my-app --template react-ts
System Info
System:
OS: macOS 11.6
CPU: (8) arm64 Apple M1
Memory: 128.70 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
Yarn: 1.22.15 - ~/.nvm/versions/node/v16.14.2/bin/yarn
npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
Browsers:
Chrome: 103.0.5060.134
Firefox: 103.0.1
Safari: 15.4
Safari Technology Preview: 15.4
Used Package Manager
yarn
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.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Typescript Types for import.meta.env - vue.js - Stack Overflow
I've tried the following but does not work. declare global { namespace NodeJS { interface ImportMeta { GITHUB_AUTH_TOKEN: string; NODE_ENV: ' ...
Read more >Features | Vite
Vite supports importing .ts files out of the box. Vite only performs transpilation on .ts files and does NOT perform type checking. It...
Read more >import-meta-resolve - npm
Start using import-meta-resolve in your project by running `npm i import-meta-resolve`. There are 87 other projects in the npm registry ...
Read more >Vite-plugin-glob - npm.io
There are quite some scenarios that import.meta.glob wasn't considered when it's been implemented at the beginning. So we received quite a few PRs...
Read more >ImportMeta | Runtime APIs - Deno
Deno provides extra properties on `import.meta`. These are included here to ensure that these are still available when using the Deno namespace in ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

same issue, add
import 'vite/client'to a shared.d.tsfile in project fix it.