Skip to main content

Fetch polyfills

Public beta for Mapbox Search JS
Mapbox Search JS is in public beta. During the public beta phase, frameworks may be subject to potential changes as they stabilize.

When running Search JS Core in a Node.js environment, the global fetch implementation must be polyfilled.

This can be done either through a global polyfill (for example, import 'cross-fetch/polyfill';) or by passing in a fetch object directly into the polyfillFetch function below. We recommend using well-supported libraries like cross-fetch or node-fetch.

polyfillFetch

Polyfills fetch implementation used in Search JS Core.

If a fetch implementation is already available, the polyfill will be silently ignored.

When running Search JS Core in a Node.js environment, fetch must be either polyfilled globally or passed into this function before usage of internal library functionality.

Parameters

opts(FetchImplementation) Options for the polyfill.
NameDescription
opts.AbortController
AbortController
Required. A custom AbortController implementation.
opts.fetch
fetch
Required. A custom fetch implementation.
force(boolean)(default false) If true , the polyfill will be forced to load. Otherwise, it will only load if fetch is not available.

Returns

void
Was this section on polyfillFetch helpful?
Was this page helpful?