-
Notifications
You must be signed in to change notification settings - Fork 98
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
webpack build error: document is not defined #14
Comments
* fix for document is not defined possibke solution for #14 * bump version to 2.1.2
Do me a favor. Try this out with version 2.1.2. I have a small fix that used |
Now the error is: Cannot read property 'body' of undefined. |
This is happening in SSR/SSG tools because
I'd probably lean towards the first approach as it doesn't change your public API. Maybe there are better solutions? Note: this will be a problem in |
looking to do this in const noop = () => {};
const defaultElement = (global.document && global.document.body) || {
classList: {
add: noop,
remove: noop,
},
};
const defaultConfig = {
classNameDark: defaultClassNameDark,
classNameLight: defaultClassNameLight,
element: defaultElement,
}; basically, this will provide a mock element with a Overkill? Thoughts? I haven't worked with SSR at all. But before I do, I have to fix |
I suggested that type of approach in a similar project a while back but now I'm not sure it really matters. Whatever is cleanest/easiest to maintain is probably fine since all we're doing is faking it out to make it build. Hmm, the no-flash solution might be in jeopardy here. 🤔 |
the no-flash code only runs client-side as it's included in |
I was thinking it might get evaluated during build but it shouldn't. 👍 (For a lot of these SSR/SSG tools, there isn't an |
@fxbabys I've create an alpha for you to test against. Test it by installing:
I tested it myself with an SSR test app, but would like you to verify before I put the code into the |
It works now, and I can also pass my custom config. Thank you ! |
nice! I'll create a real @allcontributors[bot] please add @fxbabys for userTesting and bug |
I've put up a pull request to add @fxbabys! 🎉 |
@allcontributors[bot] please add ideas to @wKovacs64 |
I've put up a pull request to add @ideas! 🎉 |
arrg. merge conflict. again... @allcontributors[bot] please add ideas to @wKovacs64 |
I've put up a pull request to add @ideas! 🎉 |
one more time... @allcontributors[bot] please add ideas to @wKovacs64 |
I've put up a pull request to add @ideas! 🎉 |
I don't think that worked. 😄 (The bot, I mean. The changes in |
yeah. the bot is a little finicky. i'll have to manually back it out and add |
Hey! Thanks for using the bot :) I think it's expecting the syntax |
@fxbabys I pushed the SSR support into 2.2.1 ( Thx! |
Sure, and it still works. 😄 |
I am planning to add dark mode for my website and import this package, it works in development but when building it throws an error: document is not defined. I tried to pass the optioalConfigObject but still get the error.
The text was updated successfully, but these errors were encountered: