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

🐛 BUG: process.env.XXX not accessible #2244

Closed
gqio opened this issue Dec 21, 2021 · 8 comments
Closed

🐛 BUG: process.env.XXX not accessible #2244

gqio opened this issue Dec 21, 2021 · 8 comments

Comments

@gqio
Copy link

gqio commented Dec 21, 2021

What version of astro are you using?

0.21.13

What package manager are you using?

pnpm

What operating system are you using?

Mac

Describe the Bug

Unable to access process.env.XXX directly.

XXX=true astro build/dev

---
console.log(process.env.XXX) // output undefined
console.log(process.env) // output correctly an object with a prop XXX and value 'true'
const {XXX}= process.env
console.log(XXX)// output  correctly 'true'
---

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-haaaff?file=src%2Fpages%2Findex.astro&on=stackblitz

@matthewp
Copy link
Contributor

That is very strange! I cleaned up the example a little bit: https://stackblitz.com/edit/github-haaaff-nxqfrw?file=src%2Fpages%2Findex.astro&on=stackblitz

@gqio
Copy link
Author

gqio commented Dec 22, 2021

Yes, indeed it caused us some trouble because it was correctly processed before our migration from the 0.20.x to 0.21.x
And it was used to inject plugins and scripts only on certain conditions but with 0 errors during the build.

@natemoo-re
Copy link
Member

I think this is a Vite limitation. Vite does support process.env access but only in 2.7.x. Astro is still pinned to 2.6.x while we work on #1866

@zyj1022
Copy link

zyj1022 commented Jan 18, 2022

process.env.NODE_ENV can be development, but NODE_DEBUG is undefinded

@natemoo-re
Copy link
Member

Moved the Vite upgrade to #2424. Once that lands this will be unblocked.

@tony-sull
Copy link
Contributor

#2424 landed!

Closing this out since it should be supported now that we are using Vite 2.7 🥳

@natemoo-re natemoo-re reopened this Feb 17, 2022
@natemoo-re
Copy link
Member

Re-opening this! It looks like you can access process.env now, but it doesn't expose the local environment variables defined in .env files.

@natemoo-re
Copy link
Member

OK, I did some more testing! You should be able to access process.env.XXX now in [email protected] and up. The caveat is that process.env will not include variables defined on process.env.

I just opened #2612 to expose all variables defined in .env to import.meta.env during SSR. Together, this will hopefully address all of your needs!

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

No branches or pull requests

5 participants