mapbox / mapbox/mapbox-gl-directions

XMLHttpRequest is not defined

Open
#289 10 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug
Dominant language
JavaScript
Stars
255
Forks
130
PR merge metrics
No merged PRs in 30d

Description

I'm building a React app using Remix (SSR) and ran into issues with XMLHttpRequests in this package, which aren't supported by Node. My workaround was to use yarn patch and packageExtensions to add xhr2 as a dependency and replace the existing requests in dist/mapbox-gl-directions.js.

Wondering if anyone else has encountered this and if there might have been a better solution. I noticed that the demo @teaden made had no issues so I'm thinking it might have to do with using an SSR framework.

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

Reproduce the XMLHttpRequest failure in a Remix SSR environment and inspect dist/mapbox-gl-directions.js, comparing its requests with the yarn patch and packageExtensions workaround using xhr2. Done would mean identifying and agreeing on an SSR-compatible request approach, with the behavior verified in the reported React and Node context.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, react
Domain
api, frontend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.