mapbox / mapbox/mapbox-gl-geocoder

mapbox-gl-geocoder prevent server side rendering on Node by eagerly using browser api

Open
#366 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
388
Forks
181
PR merge metrics
No merged PRs in 30d

Description

It seems that mapbox-gl-geocoder is using "suggestions" that eagerly use browser API.
This prevent Node to server side render.

ReferenceError: window is not defined
at Object. ((mypath)\suggestions\index.js:59:1)
at Module._compile (internal/modules/cjs/loader.js:799:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:810:10)
at Module.load (internal/modules/cjs/loader.js:666:32)
at tryModuleLoad (internal/modules/cjs/loader.js:606:12)
at Function.Module._load (internal/modules/cjs/loader.js:598:3)
at Module.require (internal/modules/cjs/loader.js:705:19)
at require (internal/modules/cjs/helpers.js:14:16)
at Object. ((mypath)\node_modules@mapbox\mapbox-gl-geocoder\lib\index.js:3:17)
at Module._compile (internal/modules/cjs/loader.js:799:30)

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

Inspect suggestions/index.js around line 59 and the import from lib/index.js, using the reported ReferenceError as the starting point. Confirm that requiring the package in Node no longer accesses the browser API eagerly, and verify the server-side rendering entry point can load without window being defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.