importMetaEnv doesn't work.
See original GitHub issueDescribe the bug
I used the intellisense function as per the guide, but it doesn’t work.
/src/env.d.ts
interface ImportMetaEnv {
VITE_API_TIMEOUT: number,
VITE_MOCKUP: boolean
}
.env
VITE_API_TIMEOUT=3000
VITE_MOCKUP=true
And, when import.meta.env is printed from main.ts to the console…
BASE_URL: "/"
DEV: true
MODE: "development"
PROD: false
SSR: false
VITE_API_TIMEOUT: "3000"
VITE_MOCKUP: "true"
VITE_SET: "900"
Intellisense does not work for .env settings. It only comes in string type.
Reproduction
I want it to be converted to the type applied in intellisense (env.d.ts
).
System Info
package.json
"devDependencies": {
"@antfu/eslint-config": "^0.6.5",
"@iconify/json": "^1.1.347",
"@intlify/vite-plugin-vue-i18n": "^2.1.2",
"@types/nprogress": "^0.2.0",
"@typescript-eslint/eslint-plugin": "^4.24.0",
"@vitejs/plugin-vue": "^1.2.2",
"@vue/compiler-sfc": "^3.0.11",
"@vue/server-renderer": "^3.0.11",
"cross-env": "^7.0.3",
"eslint": "^7.27.0",
"https-localhost": "^4.6.5",
"markdown-it-prism": "^2.1.6",
"npm-run-all": "^4.1.5",
"pnpm": "^6.4.0",
"sass": "^1.34.0",
"typescript": "^4.2.4",
"vite": "^2.3.3",
"vite-plugin-components": "^0.9.1",
"vite-plugin-icons": "^0.5.1",
"vite-plugin-md": "^0.6.7",
"vite-plugin-pages": "^0.12.1",
"vite-plugin-pwa": "^0.7.3",
"vite-plugin-vue-layouts": "^0.3.1",
"vite-plugin-windicss": "^0.15.10",
"vite-ssg": "^0.11.1",
"vue-tsc": "^0.1.4"
}
Used package manager: pnpm
Issue Analytics
- State:
- Created 2 years ago
- Comments:23 (14 by maintainers)
Top Results From Across the Web
Getting Env variables to work with import.meta.env #9000
I am trying to get some environment variables to work but for the life of me I can not...I have looked through a...
Read more >Import.meta.env undefined on production build vitejs
I am using vitejs to compile my react app statically, however after build . env imports become undefined which is not the case...
Read more >Env Variables and Modes - Vite
Vite exposes env variables on the special import.meta.env object. ... For example, dynamic key access like import.meta.env[key] will not work.
Read more >import.meta - JavaScript - MDN Web Docs
The import.meta meta-property exposes context-specific metadata to a JavaScript module. It contains information about the module, ...
Read more >Import env / process env imports VUE 3 vite - Laracasts
Hello, i want to import my back-end url from .env i need to import it in something like this. but it doesn't work....
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
Recommended in docs way to add types causes build problem:
This works
@imShara I can confirm this 👍
Correct would be without
extends Readonly<Record ...
and maybe I think with the///ref