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

Getting "window is not defined" in client/overlay.js after upgrading to webpack-dev-server 4.12 #4774

Closed
cakoose opened this issue Mar 16, 2023 · 4 comments · Fixed by #4773

Comments

@cakoose
Copy link

cakoose commented Mar 16, 2023

Bug report

  1. I have a tiny repo that uses webpack-dev-server.
  2. I use webpack serve and view the page in a browser.
  3. This works fine with webpack-dev-server 4.11.1. But when I upgrade to 4.12, I get an error page.

Actual Behavior

With 4.12, I get an error page:

Uncaught ReferenceError: window is not defined
    at eval (webpack://monaco-utf8-length-incremental/./node_modules/webpack-dev-server/client/overlay.js?:247:56)

Screenshot:
Screen Shot 2023-03-16 at 16 08 13

Expected Behavior

With 4.11.1, the expected page loads. It's a page with the Monaco text editor that shows a character count at the bottom.

How Do We Reproduce?

To get the expected behavior (webpack-dev-server 4.11.1):

  1. git clone https://github.com/cakoose/monaco-utf8-length-incremental
  2. git checkout 8ed7c9430db129788418dc20f4a39eb089164c14
  3. yarn run start
  4. Point your browser at http://localhost:8080
  5. See that the page loads

To the the error behavior (webpack-dev-server 4.12):

  1. Edit "package.json" and edit the "webpack-dev-server" depenency from "4.11.1" to "4.12"
  2. yarn install
  3. yarn run start
  4. Point your browser at http://localhost:8080
  5. See the error page.

Please paste the results of npx webpack-cli info here, and mention other relevant information

System:
  OS: macOS 12.6.3
  CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Memory: 256.44 MB / 32.00 GB
Binaries:
  Node: 18.14.1 - ~/.volta/tools/image/node/18.14.1/bin/node
  Yarn: 3.4.1 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
  npm: 9.3.1 - ~/.volta/tools/image/node/18.14.1/bin/npm
Browsers:
  Chrome: 111.0.5563.64
  Edge: 111.0.1661.44
  Firefox: 111.0
  Safari: 16.3
Packages:
  css-loader: 6.7.3 => 6.7.3
  file-loader: 6.2.0 => 6.2.0
  html-webpack-plugin: 5.5.0 => 5.5.0
  style-loader: 3.3.2 => 3.3.2
  ts-loader: 9.4.2 => 9.4.2
  webpack: 5.76.2 => 5.76.2
  webpack-cli: 5.0.1 => 5.0.1
  webpack-dev-server: 4.12.0 => 4.12.0
@alexander-akait
Copy link
Member

Yeah, good catch, @malcolm-kee fix is easy, if no document.window do nothing, why it happens - some applications have workers and don't exclude dev server client for entries (because it requires more setup), but it is not critical because it is just dev env, so to avoid it let's do nothing

@alexander-akait
Copy link
Member

@cakoose Will fix in near future

@cakoose
Copy link
Author

cakoose commented Mar 17, 2023

Glad to hear that there's an easy fix!

Separately, I was curious about this comment:

some applications have workers and don't exclude dev server client for entries (because it requires more setup)

Is there some setup I can do to be more "correct"?

@jagribble
Copy link

Also getting this issue.

don't exclude dev server client for entries (because it requires more setup)

Is there an example of this setup?

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

Successfully merging a pull request may close this issue.

3 participants