Error: 'window is not defined' with Webpack 4
See original GitHub issueI’m posting this issue for reference more than anything else, in case others are searching for a fix. The temporary fix is at the end, perhaps it’s worth adding that to the README?
When using this plugin with a fresh install of Webpack 4 (4.6.0 in my test) I get the following error:
ERROR in ReferenceError: window is not defined
Having dug into it further, it appears it is a side effect of this issue where the umd target generates invalid code for running inside a Node.js context.
The temporary fix is detailed here, where you can add the following to your Webpack config to change the global keyword from window to this:
output: {
  // ...
  globalObject: "this"
}
Issue Analytics
- State:
 - Created 5 years ago
 - Reactions:59
 - Comments:20
 
Top Results From Across the Web
[SOLVED] Webpack: Error in window is not defined during ...
Error blinks up during execution of "node node_modules/webpack/bin/webpack.js --mode=production --env.prod" command. What is the expected ...
Read more >Window is not defined after a build with Webpack
js it gives me this error: ReferenceError: window is not defined. const webpack = require('webpack'); const merge = require('webpack-merge'); ...
Read more >Window is not defined after a build with Webpack-Reactjs
Using global worked for me. const window = global.window if (window && window.localStorage) { const storageLogLevel = window.localStorage.
Read more >'window' is undefined in umd library output for Webpack4
This is a bug of Webpack4. A workaround is to add globalobject to the output in the webpack config. output: { path: resolve(__dirname,...
Read more >To v5 from v4 - webpack
Upgrade webpack 4 and its plugins/loaders · Make sure your build has no errors or warnings · Make sure to use mode ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

i added
globalObject: "this"still not fix ERROR in window is not definedup