Skip to content
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

Cannot reassign procces.env.NODE_ENV in ssr #6975

Closed
7 tasks done
sheremet-va opened this issue Feb 18, 2022 · 3 comments · Fixed by #6989
Closed
7 tasks done

Cannot reassign procces.env.NODE_ENV in ssr #6975

sheremet-va opened this issue Feb 18, 2022 · 3 comments · Fixed by #6989

Comments

@sheremet-va
Copy link
Member

Describe the bug

I can assign process.env.NODE_ENV, but when accessing it it gets statically replaced.

process.env.NODE_ENV = '123'
console.log(process.env.NODE_ENV)

transformed to

process.env.NODE_ENV = '123'
console.log("test")

This is probably because of the define plugin:

https://github.com/vitejs/vite/blob/6d4ee18e0c45e7c1fedd36c24b631a8f97f40c0f/packages/vite/src/node/plugins/define.ts

Reproduction

vitest-dev/vitest#789

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz
    Memory: 10.73 GB / 15.90 GB
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 98.0.4758.102
    Edge: Spartan (44.22000.120.0), Chromium (98.0.1108.55)
    Internet Explorer: 11.0.22000.120

Used Package Manager

pnpm

Logs

No response

Validations

@poyoho
Copy link
Member

poyoho commented Feb 18, 2022

hi @sheremet-va
vitest use serve mode and use ssr options transform will pass in define plugin. I think the reason in https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/clientInjections.ts#L52-L60.

🙈 maybe process.env['NODE_ENV'] will pass.

and after #6970 will be pass?

@sheremet-va
Copy link
Member Author

hi @sheremet-va vitest use serve mode and use ssr options transform will pass in define plugin. I think the reason in https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/clientInjections.ts#L52-L60.

🙈 maybe process.env['NODE_ENV'] will pass.

and after #6970 will be pass?

After #6970 it does not pass

@poyoho
Copy link
Member

poyoho commented Feb 18, 2022

oh sorry you are right. processNodeEnv is no pass in ssr mode

@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants