question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: 'window is not defined' with Webpack 4

See original GitHub issue

I’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:open
  • Created 5 years ago
  • Reactions:59
  • Comments:20

github_iconTop GitHub Comments

22reactions
dongdongmaocommented, Oct 29, 2018

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

8reactions
ufhycommented, Jan 19, 2019

up

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found