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

Document not defined #793

Closed
ghost opened this issue Apr 26, 2022 · 3 comments
Closed

Document not defined #793

ghost opened this issue Apr 26, 2022 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 26, 2022

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Getting the stacktrace mentioned on issue 785 during build step on next v12. It was not a problem on prior major versions.

If the current behavior is a bug, please provide the steps to reproduce and possibly a minimal demo or testcase in the form of a Next.js app, CodeSandbox URL or similar

This could be difficult as I myself ran across this bug at work and could not reproduce this error locally at home.

What is the expected behavior?

It should'nt throw the error.

Environment (include versions)

  • Version of styled-jsx (or next.js if it's being used): Next 12.1.5
  • Browser: N/A (Build issue)
  • OS: Windows 10

Did this work in previous versions?

Yes, upto Next v11.1.4

@ghost
Copy link
Author

ghost commented Apr 26, 2022

I wanted to add that the issue can be solved by making these changes on index.js (Credit goes to: abbasEbadian as mentioned on issue 785)

From:
const node = this._isBrowser && document.querySelector('meta[property="csp-nonce"]');

To:
const node = this._isBrowser && (typeof document !== "undefined") && document.querySelector('meta[property="csp-nonce"]');

I could have raised a PR for this, but I can see that there is a similar PR from AaronO, which is meant for Deno, but I guess it would solve this particular issue as well :)

@huozhi
Copy link
Member

huozhi commented Apr 26, 2022

What environment are you using that requires extra checking for determing browser? Can you provide a minimal reproduction?

The reason we're holding #769 is because typeof window is widly used by many libraries need to be run in nodejs+browser, if we need to support this by changing the condition it will reflect lots of existing libraries. And any new created runtime could customize the global variables, it's better to find a way to balance it rather than changing all libraries to support a new env. But if later we really have to change it, we could adopt it.

@ghost
Copy link
Author

ghost commented Jun 19, 2022

I'm closing this issue. Turns out, it was a mistake from our end, some dude had reconfigured window to be an empty object at the top level -_-
once i had fixed that, it started to work as intended.

But, what still bugs me though is that that code was written some time back and the builds were still passing up till v12. oh well...

thank you nonetheless :)
sorry abt the confusion :(

@ghost ghost closed this as completed Jun 19, 2022
This issue was closed.
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
@huozhi and others