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 is undefined" in WebWorker when importing styles from css module #16

Open
w1ndy opened this issue Jan 21, 2018 · 5 comments · May be fixed by #17
Open

"document is undefined" in WebWorker when importing styles from css module #16

w1ndy opened this issue Jan 21, 2018 · 5 comments · May be fixed by #17

Comments

@w1ndy
Copy link

@w1ndy w1ndy commented Jan 21, 2018

var styleElement = document.querySelector('style[data-vue-ssr-id~="' + obj.id + '"]')

document could be undefined if a style file is required from a WebWorker.

@w1ndy w1ndy linked a pull request that will close this issue Jan 21, 2018
@yyx990803
Copy link
Member

@yyx990803 yyx990803 commented Jan 24, 2018

Are you running a webpack bundle inside a web worker? Can you be more specific about your use case?

@w1ndy
Copy link
Author

@w1ndy w1ndy commented Jan 24, 2018

@yyx990803
See here for a bug repro.
In the browser, the webworker fails to run, and addStylesClient.js throws Uncaught ReferenceError: document is not defined.

@yyx990803
Copy link
Member

@yyx990803 yyx990803 commented Jan 24, 2018

I know it has problems in workers, what I'm trying to understand is why you are using it inside a worker, since the worker has no access to the DOM. Are you trying to render Vue components in a worker?

@w1ndy
Copy link
Author

@w1ndy w1ndy commented Jan 25, 2018

Just like what I’ve demonstrated in the repro, the worker just reads some exported constants from a CSS module.
In my real use case, I define several constants that control the style (like color, width and height of views, etc) and share them using CSS modules between Vue components and workers, which generate geometry data asynchronously for canvas drawing. The trouble is that I cannot access these constants within workers because vue-style-loader relies on document to do some preprocessing.

@destroytoday
Copy link

@destroytoday destroytoday commented Jul 6, 2018

I’m experiencing this now when bundling a component package with config.css.extract = false and importing it into a Nuxt app. Since there’s a condition for SSR anyway, could we simply check for document like var styleElement = document && document.querySelector(...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.