Skip to content
This repository has been archived by the owner on Jul 10, 2021. It is now read-only.

Use process ENVs also in template sections #60

Closed
frederikhors opened this issue Sep 20, 2020 · 5 comments
Closed

Use process ENVs also in template sections #60

frederikhors opened this issue Sep 20, 2020 · 5 comments

Comments

@frederikhors
Copy link
Contributor

frederikhors commented Sep 20, 2020

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.

😄

@dominikg
Copy link
Owner

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.

@frederikhors
Copy link
Contributor Author

Yeah, using const is fine, but sometimes people use that ENVS in template sections, you know.

@dominikg
Copy link
Owner

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.

@frederikhors
Copy link
Contributor Author

I think they fixed it today! sveltejs/svelte#5422

@dominikg
Copy link
Owner

for the record. svite-0.7.1 has updated svelte peerDependency to 3.26.0. You should be able to use it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants