1

I am getting a different error and can not seem to figure it out now for a coupe of hours,

Here's my code :

createMapMarkers(boatData) {
 console.log('DATA :'+boatData);
 const newMarkers = boatData.map((boat) => {
 return {
 title : boat.Name,
 location : {
 Latitude : boat.Geolocation__Latitude__s,
 Longitude : boat.Geolocation__Longitude__s
                }
            }
        });
 newMarkers.unshift({
 title : LABEL_YOU_ARE_HERE,
 icon : ICON_STANDARD_USER,
 location : {
 Latitude : this.latitude,
 Longitude : this.longitude
            }
        });
 
 this.mapMarkers = newMarkers;
 this.isLoading = false;
    }

I am getting this error :

modules/c/boatsNearMe.js:4 Uncaught (in promise) TypeError: LWC component's u/wire target property or method threw an error during value provisioning. Original error:
[e.map is not a function]
    at h.createMapMarkers (modules/c/boatsNearMe.js:4)
    at h.wiredBoatsJSON (modules/c/boatsNearMe.js:4)
    at b.dispatchEvent (aura_prod.js:6)
    at yi (/components/force/lds.js:2)
    at eval (/components/force/lds.js:2)
    at eval (/components/force/lds.js:2)

I checked the piece of code by running on Here on Mozilla and it worked perfectly. It is only throwing error in LWC.

  • how is createMapMarkers being invoked? – salesforce-sas Jul 2 at 21:27
3

The above code has correct syntax provided boatData is an array. It looks like the Javascript object you have boatData is not an Array and hence you get an exception that .map is not a function.

You can easily reproduce this with below Javascript code

let object_x = {};
object_x.map( x => {
   return x;
});

This will result in an error Error: object_x.map is not a function

Looks like the boatData is a JSON string and you can use JSON.parse(boatData) to cast to the Javascript array.

| improve this answer | |
  • that's it, I was about to remove the question or post the answer. I over looked that Apex was returning JSON.serialize object. use JSON.parse and worked fine. Thank you. – apple123 Jul 2 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.