Skip to content

dynamic env is an empty object in production when using config.kit.env.dir #6204

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

Closed
thenbe opened this issue Aug 23, 2022 · 9 comments · Fixed by #7001
Closed

dynamic env is an empty object in production when using config.kit.env.dir #6204

thenbe opened this issue Aug 23, 2022 · 9 comments · Fixed by #7001
Assignees
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Milestone

Comments

@thenbe
Copy link
Contributor

thenbe commented Aug 23, 2022

Describe the bug

config.kit.env.dir, introduced in #6175, only works in dev.

In dev, correct env is logged to console. In prod, empty object is logged to console. Minimal reproduction below.

Reproduction

https://github.com/ambiguous48/dynamic-env-missing

Logs

No response

System Info

System:
    OS: Linux 5.18 Pop!_OS 22.04 LTS
    CPU: (24) x64 12th Gen Intel(R) Core(TM) i9-12900K
    Memory: 16.68 GB / 31.13 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 18.3.0 - ~/.local/share/pnpm/node
    Yarn: 1.22.19 - ~/.local/share/pnpm/yarn
    npm: 8.11.0 - ~/.local/share/pnpm/npm
  Browsers:
    Chrome: 104.0.5112.79
    Firefox: 103.0
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.65 
    @sveltejs/kit: next => 1.0.0-next.431 
    svelte: ^3.44.0 => 3.49.0 
    vite: ^3.0.4 => 3.0.9

Severity

annoyance

Additional Information

No response

@thenbe thenbe changed the title dynamic env is an empty project in production when using kit.config.env.dir dynamic env is an empty project in production when using config.kit.env.dir Aug 23, 2022
@thenbe thenbe changed the title dynamic env is an empty project in production when using config.kit.env.dir dynamic env is an empty object in production when using config.kit.env.dir Aug 23, 2022
@elliott-with-the-longest-name-on-github
Copy link
Contributor

Based on my testing, this should be fixed with #6179. The problem isn't even the new config.kit.env.dir option, it's that (1) we weren't initializing the variables correctly in prerendering and (2) something something, complicated initialization sequences. Either way, the repro works fine when I point it at that branch.

@benmccann
Copy link
Member

Closing this then since that PR has been merged. Note that it hasn't been released yet

@thenbe
Copy link
Contributor Author

thenbe commented Sep 1, 2022

Note that it hasn't been released yet

@benmccann This is the release that you're referring to, yes? If the answer is no feel free to disregard this.

If it is, then the issue seems to still exist even after updating to the latest sveltekit (reproduction here).

@benmccann benmccann reopened this Sep 1, 2022
@benmccann benmccann added bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. labels Sep 1, 2022
@benmccann benmccann added this to the 1.0 milestone Sep 1, 2022
@benmccann
Copy link
Member

that reproduction looks to be on the latest version and any changes from a week ago have certainly been released by now, so I'd expect it to work

@elliott-with-the-longest-name-on-github
Copy link
Contributor

I can't decide if this is intended behavior or not. On one hand, the dynamic env is populated by your adapter at runtime -- in this case, your "adapter" is SvelteKit...?

@Rich-Harris Do you think preview should respect config.kit.env.dir? I think my vote would be yes, but I want your blessing before doing anything with it.

@thenbe
Copy link
Contributor Author

thenbe commented Sep 6, 2022

Just a heads up that this issue can also be reproduced when using adapter-node then running npm run build && node build/index.js

@elliott-with-the-longest-name-on-github
Copy link
Contributor

Just a heads up that this issue can also be reproduced when using adapter-node then running npm run build && node build/index.js

This is definitely intended behavior.

@thenbe
Copy link
Contributor Author

thenbe commented Sep 7, 2022

This is definitely intended behavior.

I had falsely assumed that $env/dynamic would automatically inject .env files (a la dotenv), despite the docs stating otherwise.

Please feel free to close this issue.

@elliott-with-the-longest-name-on-github
Copy link
Contributor

This is definitely intended behavior.

I had falsely assumed that $env/dynamic would automatically inject .env files (a la dotenv), despite the docs stating otherwise.

Please feel free to close this issue.

It does in dev, obviously, but prod depends on the adapter. I'll wait to close until we hear from @Rich-Harris on whether the preview "adapter" should read .env files.

Rich-Harris pushed a commit that referenced this issue Sep 7, 2022
…6635)

It wasn't immediately clear to me, #6204, that `$env/dynamic` might be loaded differently depending on `dev`/`prod`. Because `$env/dynamic` included `.env` during `dev`, I erroneously assumed it would do the same during `prod` (a la dotenv).

The second sentence could be clearer but I don't know enough about the topic to make it so.
Rich-Harris added a commit that referenced this issue Sep 23, 2022
* respect env.dir when running preview - closes #6204

* add test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants