You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Vite replaces it to static variables, but we replace it to dynamic process.env, so users can redefine it in runtime, so solution 2 will break its usage.
related vitejs/vite#9791
Describe the bug
The
vite:env-replacer
plugin is indiscriminately replacingimport.meta.env
everywhere in a source file, including string literals and comments.For example, this test file:
...gets transformed into:
Another example:
...which results in:
Workaround
Use string concatenation to avoid the string replacement (as was done in the
importMetaEnv.test.ts
above):Solution 1: Strip literals from analysis
Use
strip-literal
on the string being scanned forimport.meta.env
:This would mimic the way Vite does it.
Solution 2: Remove
EnvReplacer
; use Viteenv
insteadVite already replaces
import.meta.env
in itsvite:define
plugin andvite:import-analysis
plugin, so this plugin seems unnecessary.Reproduction
StackBlitz
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: