Skip to content

fix(ssr): dont transform process.env. in ssr#5404

Merged
patak-cat merged 1 commit into
vitejs:mainfrom
bluwy:process-env-ssr-2
Oct 28, 2021
Merged

fix(ssr): dont transform process.env. in ssr#5404
patak-cat merged 1 commit into
vitejs:mainfrom
bluwy:process-env-ssr-2

Conversation

@bluwy
Copy link
Copy Markdown
Member

@bluwy bluwy commented Oct 24, 2021

Description

In SSR and the SSR target is node, process.env. will be left as is without transformation. Currently, process.env.FOO will always be transformed as ({}).FOO, which is undesirable when running in node.

Additional context

Supersedes #4192 by @GrygrFlzr (most of the code is borrowed there and we should attribute GrygrFlzr too)
Fixes #3176

Re #3176 (comment), @benmccann and I had agreed that we should continue replacing process.env. in client, but also warn the user that it would be undefined. I can make another PR for this if is desirable.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Comment thread packages/vite/src/node/plugins/define.ts
@patak-cat patak-cat merged commit 1140981 into vitejs:main Oct 28, 2021
@bluwy bluwy deleted the process-env-ssr-2 branch October 28, 2021 15:24
@sphinxc0re
Copy link
Copy Markdown

It seems to me like this did not fix the problem. process.env. is still replaced in production builds with adapter-node in sveltekit

@bluwy
Copy link
Copy Markdown
Member Author

bluwy commented Nov 4, 2021

@sphinxc0re This fix isn't released in the latest SvelteKit version yet. We're waiting for a stable Vite release before doing so.

@sphinxc0re
Copy link
Copy Markdown

Oh! Okay, I didn't know that 😅 my bad

@sebazelonka
Copy link
Copy Markdown

It seems to me like this did not fix the problem. process.env. is still replaced in production builds with adapter-node in sveltekit

any workaround to make it work?

@bluwy
Copy link
Copy Markdown
Member Author

bluwy commented Dec 3, 2021

You can temporarily do process.env["SOMETHING"] as mentioned in #3176. Though Vite 2.7.0 should be coming soon now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handling server-side/sensitive/runtime variables

6 participants