Wade
Wade
CDCloudflare Developers
Created by Wade on 1/21/2024 in #workers-help
Target node environment when building with wrangler
I'm trying to use @mapbox/mapbox-sdk in my worker, however they have a browser entry point defined in their package.json which relies on window.XMLHttpRequest object being present, which causes the following error
[wrangler:err] ReferenceError: window is not defined
at createRequestXhr (file:///<snip>/worker/node_modules/@mapbox/mapbox-sdk/lib/browser/browser-layer.js:105:13)
at null.<anonymous> (file:///<snip>/worker/node_modules/@mapbox/mapbox-sdk/lib/browser/browser-layer.js:115:15)
[wrangler:err] ReferenceError: window is not defined
at createRequestXhr (file:///<snip>/worker/node_modules/@mapbox/mapbox-sdk/lib/browser/browser-layer.js:105:13)
at null.<anonymous> (file:///<snip>/worker/node_modules/@mapbox/mapbox-sdk/lib/browser/browser-layer.js:115:15)
Is it possible to either polyfill window.XMLHttpRequest, or target a node environment when bundling via wrangler?
2 replies