Use process ENVs also in template sections
frederikhors opened this issue · comments
Summary
Before Svite I was using <div>{process.env.MY_ENV_FROM_FILE}</div>
.
Now (because of this: https://github.com/vitejs/vite#modes-and-environment-variables) I have to use import.meta.env.VITE_MY_ENV_FROM_FILE
and it works in JS code.
But I need to use it also in my html sections, like this: <div>{import.meta.env.VITE_MY_ENV_FROM_FILE}</div>
.
But it doesn't work: Cannot use 'import.meta' outside a module
.
Proposed Solution
Use process ENVs also in template sections, please.
😄
what about
<script>
let world = import.meta.env.VITE_WORLD;
</script>
<h1>Hello {world}</h1>
Does that also cause an error?
If you absolutely need to use import.meta.env in the template and believe this to be a bug please add a proper reproduction and error logs that show when/how this is happening.
Yeah, using const is fine, but sometimes people use that ENVS in template sections, you know.
The error message is directly from the svelte compiler. If you absolutely need this to work, bring it up on svelte discord.
But i'd recommend declaring a const and use that.
I think they fixed it today! sveltejs/svelte#5422
for the record. svite-0.7.1 has updated svelte peerDependency to 3.26.0. You should be able to use it