node.jsgoogle-cloud-functionsmapkitjsdommapkit-js

How can I fix 'window is undefined' when running Mapkit JS in Node.js (Firebase Functions)


I have been using Apple Mapkit JS POI search and reverseGeoLocation search in the browser and want to move my code to Firebase functions (node.js).

I can import mapkit using mapkit-npm (or just downloading the latest CDN file and importing that directly).

When I declare mapkit using const mapkit = require() I get an error "window is undefined".

I have tried to use NPM jsDOM to create a window object, but I'm still getting errors which I think are due to fields missing on either my window or navigator objects. (errors such as "Cannot perform toLowerCase on undefined").

Please can someone help me run mapkit in a non-browser environment?

Thanks :)


Solution

  • Answered in the comments - unfortunately the non-DOM aspects of mapkit are currently tied up in the browser part of the module, so they can't be used outside of a browser and therefore can't be used server side.

    I was trying to use the geolocation ones as they're much cheaper than google (and provide all the info needed in one request).

    Nevermind!