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 request: document is not defined #181

Open
gabrielzevedo opened this issue Jun 11, 2024 · 0 comments
Open

Fix request: document is not defined #181

gabrielzevedo opened this issue Jun 11, 2024 · 0 comments

Comments

@gabrielzevedo
Copy link

Using type: 'style', i have this error in my Nextjs application: ReferenceError: document is not defined;

Maybe it's worth checking if the document exists before referencing it

const styleModule = (cssText: string, nonce?: string) => nonce ? `\
const css = \`${cssText.replace(/([$`\\])/g, '\\$1')}\`;
const style = document.createElement("style");
style.setAttribute("nonce", ${nonce});
style.appendChild(document.createTextNode(css));
document.head.appendChild(style);
export {css};
` : `\
const css = \`${cssText.replace(/([$`\\])/g, '\\$1')}\`;
document.head
.appendChild(document.createElement("style"))
.appendChild(document.createTextNode(css));
export {css};

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

1 participant