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

fix(nuxt-img): access prerender.env only in server side #661

Merged
merged 2 commits into from
Nov 28, 2022

Conversation

chadsr
Copy link
Contributor

@chadsr chadsr commented Nov 24, 2022

resolves #660

@chadsr chadsr changed the title check if process is undefined before accessing prerender env fix: check if process is undefined before accessing prerender env Nov 24, 2022
@brunodeangelis
Copy link

Tested and indeed fixes the issue. Thank you @chadsr

@slavanossar
Copy link

Could also just do

if (process?.env?.prerender) {
  //...
}

@chadsr
Copy link
Contributor Author

chadsr commented Nov 25, 2022

Could also just do

if (process?.env?.prerender) {
  //...
}

Good point... I've switched it over to that syntax.
For some reason I was thinking optional chaining would still throw on process being undeclared, but it does not.

@slavanossar
Copy link

slavanossar commented Nov 27, 2022

Could also just do

if (process?.env?.prerender) {
  //...
}

Good point... I've switched it over to that syntax. For some reason I was thinking optional chaining would still throw on process being undeclared, but it does not.

Actually sorry, you are right about this. I just ran nuxi generate and when loading the page in the browser an error is thrown ReferenceError: process is not defined, wasn't happening when checking with nuxi dev which threw me off.

@chadsr
Copy link
Contributor Author

chadsr commented Nov 27, 2022

Could also just do

if (process?.env?.prerender) {
  //...
}

Good point... I've switched it over to that syntax. For some reason I was thinking optional chaining would still throw on process being undeclared, but it does not.

Actually sorry, you are right about this. I just ran nuxi generate and when loading the page in the browser an error is thrown ReferenceError: process is not defined, wasn't happening when checking with nuxi dev which threw me off.

Looks like I fell for the same trap and only ran nuxi dev when checking as well.
I've reverted it back to checking with typeof now.

@pi0 pi0 changed the title fix: check if process is undefined before accessing prerender env fix(nuxt-img): access prerender.env only in server side Nov 28, 2022
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pi0 pi0 merged commit bc9ddc0 into nuxt:main Nov 28, 2022
procrates pushed a commit to procrates/nuxt-image that referenced this pull request Feb 21, 2023
* check if process is undefined before accessing prerender env

* Update src/runtime/components/nuxt-img.ts

Co-authored-by: pooya parsa <[email protected]>
@pi0 pi0 mentioned this pull request Mar 31, 2023
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.

[nuxt3] Static image prerendering results in "process is not defined"
6 participants