-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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 4.0.1 | WebWorker window is not defined
#6642
Comments
disabling hot module replacement fixed this for me. |
@rettgerst Disabling |
Is there an ETA on this? |
#6525 will fix this. As workaround with HMR: |
Closing in favor of #6525 |
@sokra Where should one add this output.globalObject? |
@kuzirashi inside the output section of webpack config. Like this: output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js'
publicPath: 'http://localhost:3000',
globalObject: 'this'
}, |
I ran into this as well, while doing some research I think I may have found a fix, previously implemented in webpack-dev-server. I believe this issue is relevant.
if so, simply changing window to self should fix the issue |
See webpack/webpack#6642 for web workers issues
终于找到解决办法了! |
The current build uses webpack 4, which outputs an undefined `window` reference and causes ``` ReferenceError: window is not defined ``` upon import via e.g. `require("cache-control-parser")` from node. Updating the webpack config fixes the error after rebuild. References: - https://stackoverflow.com/a/58718315 - webpack/webpack#6642 - https://webpack.js.org/configuration/output/#outputglobalobject
The current build uses webpack 4, which outputs an undefined `window` reference and causes ``` ReferenceError: window is not defined ``` upon import via e.g. `require("cache-control-parser")` from node. Updating the webpack config fixes the error after rebuild. References: - https://stackoverflow.com/a/58718315 - webpack/webpack#6642 - https://webpack.js.org/configuration/output/#outputglobalobject
The current build uses webpack 4, which outputs an undefined `window` reference and causes ``` ReferenceError: window is not defined ``` upon import via e.g. `require("cache-control-parser")` from node. Updating the webpack config fixes the error after rebuild. References: - https://stackoverflow.com/a/58718315 - webpack/webpack#6642 - https://webpack.js.org/configuration/output/#outputglobalobject
In case this helps anyone, if you are hitting this error in your web worker itself (from your application code using |
This addresses this comment that the workers plugin is no longer working in next@7: vercel/next-plugins#218 (comment) This is rooted in this issue, in which the fix is to configure webpack to handle non-window global objects in the client in order for it to internally handle references to the global: webpack/webpack#6642 This next plugin is meant to handle files written as WebWorkers, in which `window` as the global is undefined (in lieu of `self`), so I've decided to explicitly fallback to `self` as the global object. In addition, I've fixed a typo where a bracket was missing in the README.
Do you want to request a feature or report a bug?
Bug 🐛
What is the current behavior?
When requiring web-worker (using worker-loader) recieve error
Uncaught ReferenceError: window is not defined
.First ~50 lines of built worker file
What is the expected behavior?
To inject right template for web-workers that won't include/use
window
element.Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
Webpack config (filtered):
NPM Packages (filtered):
Operating System: OSX
10.12.6
Node.js:
v9.5.0
The text was updated successfully, but these errors were encountered: