-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running scripts that have access to Kit stores (like $env) #5886
Comments
I feel like this is out of scope of SvelteKit. |
I just want to clarify something here. I have code which isn't only for my scripts which accesses
To continue on my previous explanation, since its the shared model logic that is actually accessing Having said that, I do acknowledge that it skirts the boundary of what is "in scope" of SvelteKit. This nonetheless may still be out of scope. This As a follow-up suggestion, maybe this feature is more appropriate for a 3rd party library to implement? Is that even possible? I don't know much about the Kit codebase yet, but if the team thinks that's feasible to build, I'd be happy to give it a try and put it out there for the community. |
@dominikg has been implementing a separate vite plugin that achieves similarly to what SvelteKit has. The problem is that the plugin creates virtual files, instead of writing to the disk like SvelteKit does now, though that will change soon too. Since ESM loaders are still experimental, you can use something like vite-node to execute the file specifically that's also powered by Vite plugins. The small issue now is that there's also two ways of importing envs again (albeit similar). But come to think of it, running just vite-node without the plugin might work too as SvelteKit's env handling should be compatible with vite-node. |
IMO, this is outside the scope of Kit, though I can see the frustration. My recommendation would be to use something like |
@bluwy Awesome suggestion! It turns out that straight up |
I've run into a similar issue - this time with Vitest. I'm trying to run tests on a script that imports env vars using SvelteKit's I really want to use |
Describe the problem
I really like the
$env
store, so I migrated the whole fullstack app to access env vars only through$env
. The problem now is that I have some backend node.js scripts (database setup and migrations and such) which need to import some model code from my app. The model code imports$env
, and so I can't import those into my script because that prevents me from running my script, b/c when I try to run my script withnode my-script.js
I get an error like this...because a dep of my dep is
$env
. I need my script to be run via SvelteKit somehow in order to resolve the$env
alias.Describe the proposed solution
Something like this would be nice...
That would allow devs to run scripts which can access the
$env
store.Alternatives considered
The only alternative I can think of would be to go back to using vanilla
process.env
. This has the disadvantage of needing to manually load via something likedotenv
, as well as losing the protections of private vs public env vars, and losing the ability to statically build env values into the bundle.Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: