Skip to content

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

Description

@cakoose

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions