-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Labels
Description
Describe the bug
When building a project that uses import.meta.env.UNKNOWN, it is being replaced as MODE:"production",DEV:!1,PROD:!0}.UNKNOWN instead of ({}).UNKNOWN.
Ref #8090 (Additional context)
Bug introduced in #5972 in Vite 3. Line 50 is never being used, and skips to line 51 instead.
vite/packages/vite/src/node/plugins/define.ts
Lines 42 to 53 in 908c9e4
| const env: Record<string, any> = { | |
| ...config.env, | |
| SSR: !!config.build.ssr | |
| } | |
| for (const key in env) { | |
| importMetaKeys[`import.meta.env.${key}`] = JSON.stringify(env[key]) | |
| } | |
| Object.assign(importMetaKeys, { | |
| 'import.meta.env.': `({}).`, | |
| 'import.meta.env': JSON.stringify(config.env), | |
| 'import.meta.hot': `false` | |
| }) |
This not only happens for import.meta.env., but process.env. to for ssr builds. And other similar usage.
Reproduction
Vite 3: https://stackblitz.com/edit/vitejs-vite-b1md2x?file=main.js&terminal=build,preview
Vite 2.9: https://stackblitz.com/edit/vitejs-vite-ouwh65?file=main.js&terminal=build,preview
System Info
Vite 3Used Package Manager
pnpm
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 https://github.com/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.
Reactions are currently unavailable