mapbox / mapbox/mapbox-gl-js

window is not defined exception in prod bundle using webpack 5.99

Open
#13,528 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :lady_beetle: needs information :pray:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

mapbox-gl-js version

v3.13.0

Browser and version

Chrome Version 138.0.7204.184 (Official Build) (64-bit)

Expected behavior

The expected behavior is there are no behavioral diffs between dev and prod bundles.

Actual behavior

Hello,

I have a simple MapBox implementation with React that renders pins and clusters

These are the libraries

"react-map-gl": "8.0.4"
"mapbox-gl": "3.13.0"
"supercluster": "8.0.1"

I am using Webpack 5.99 to bundle.

Node version 24.3.0

When releasing a dev bundle - everything works fine.

When releasing a prod bundle - zooming out to a certain point is causing the map around the initial viewport to disappear (map is not rendered) and the following error is thrown:

Uncaught ReferenceError: window is not defined

Is this a known issue ?
Is it related to webpack or the lib itself ?

Any thoughts, directions or debug instructions will be highly appreciated.

Thanks,
Evgeni

Link to the demonstration

No response

Steps to trigger the unexpected behavior

No response

Relevant log output
Uncaught ReferenceError: window is not defined
    at l (608692cc-458b-4d64-aa0b-5a3f2d64e990:1:20835)
    at 608692cc-458b-4d64-aa0b-5a3f2d64e990:1:22145
    at 608692cc-458b-4d64-aa0b-5a3f2d64e990:1:22533
    at kt (608692cc-458b-4d64-aa0b-5a3f2d64e990:1:22585)
    at Ot (608692cc-458b-4d64-aa0b-5a3f2d64e990:1:23424)
    at 608692cc-458b-4d64-aa0b-5a3f2d64e990:10:213250
    at e.aI.request (608692cc-458b-4d64-aa0b-5a3f2d64e990:10:212754)
    at e.aJ [as loadVectorData] (608692cc-458b-4d64-aa0b-5a3f2d64e990:10:213165)
    at c.loadTile (608692cc-458b-4d64-aa0b-5a3f2d64e990:10:256480)
    at Ee.loadTile (608692cc-458b-4d64-aa0b-5a3f2d64e990:10:290109)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the production-only failure with mapbox-gl 3.13.0, react-map-gl 8.0.4, Webpack 5.99, and Node 24.3.0, then compare the dev and production bundles around the reported stack trace. Done means identifying whether the window access comes from the library or bundler configuration and documenting a confirmed fix or minimal reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react, webpack
Domain
build-system, frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.