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

Built in Vite env vars seem incorrect in prerender hook #25

Closed
gryphonmyers opened this issue Mar 31, 2021 · 7 comments
Closed

Built in Vite env vars seem incorrect in prerender hook #25

gryphonmyers opened this issue Mar 31, 2021 · 7 comments

Comments

@gryphonmyers
Copy link
Contributor

Repro Steps:

  1. Add a console.log of import.meta.env from inside a page's prerender hook
  2. Run prerender process, e.g. cross-env NODE_ENV=production && npm run build && vite-plugin-ssr prerender --clientRouter
  3. Observe that logged env indicates the following:
MODE: 'production'
DEV: true
PROD: false

Expected Results:
Having specified NODE_ENV=production, I would expect DEV=false, PROD=true. Additionally, I would expect SSR=true to come through, but it is not showing up at all.

@brillout
Copy link
Member

Seems like a Vite bug. I will have a look.

brillout added a commit that referenced this issue Apr 3, 2021
@brillout
Copy link
Member

brillout commented Apr 3, 2021

Couldn't reproduce. The output in 764e8e5 is correct.

Note that your cross-env NODE_ENV=production has no effect in your cross-env NODE_ENV=production && npm run build && vite-plugin-ssr prerender --clientRouter. Use cross-env without &&: 764e8e5#diff-3ae58cd0dc48e9afc5345bcd388b6f82b75345c9fd156f5bd3c71cb92037aa64R6. If you were to add && like this "prod:server": "cross-env NODE_ENV=production && ts-node ./server" then it wouldn't work.

But that besides the point since it should work nevertheless and simply doing npm run build && vite-plugin-ssr prerender --clientRouter should work.

@gryphonmyers
Copy link
Contributor Author

Oh dear. I will try again with the commit you have referenced to see if I can figure out why I was getting different results.

@brillout
Copy link
Member

brillout commented Apr 4, 2021

No worries. The commit lives in the reprod-25 branch https://github.com/brillout/vite-plugin-ssr/tree/reprod-25.

@gryphonmyers
Copy link
Contributor Author

OK now I am getting DEV: false, PROD: true, which would be correct, however I am still not seeing SSR populated at all. Were you seeing evidence of SSR env being set inside of prerender hooks as well?

@brillout
Copy link
Member

brillout commented Apr 6, 2021

Yes I can confirm that the SSR env is missing in prod. I'm confident the problem is on Vite's side. It should be easy to reproduce on https://github.com/vitejs/vite/tree/main/packages/playground/ssr-vue.

@gryphonmyers
Copy link
Contributor Author

OK going to go ahead and close this then. For clarity, I believe the fix here was removeing && in my npm script per brillout's suggestion.

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

2 participants