Next.js Discord

Discord Forum

.map is not a function error

Answered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
I am building a site to track key metrics for my state senators using App Router.

I am getting this error:
Error: _util_senator_js__WEBPACK_IMPORTED_MODULE_1___default(...).map is not a function

I have this component:
import Image from 'next/image';

export default function SenatorCard({
  firstName,
  lastName,
  district,
  party,
  yearElected,
}) {
  return (
    <div>
      <Image 
        src={photoURL} 
        alt={photoOfSenator`${lastName}`} />
      <h3>
        {firstName} {lastName}
      </h3>
        <p>{district}</p>
        <p>{yearElected}</p>
        <p>{party}</p>
     </div>
  );
}


This is my page:

import senatorList from '../../../../(util)/senator.js';

import SenatorCard from '../../../../(components)/SenatorCard.js';

export default async function Senator() {
  return (
    <>
      <h1>
        This is a list of Senators for the great state of Connecticut!
      </h1>
      {senatorList.map((d) => (
        <SenatorCard
          key={d.id}
          firstName={d.firstName}
          lastName={d.lastName}
          district={d.district}
          party={d.party}
          yearElected={d.yearElected}
          photoURL={d.photoURL}
        />
      ))}
    </>
  );
}


Not sure what I am doing wrong here...
Answered by Rohu
did you export it in senator.js?
View full answer

3 Replies

Cape lionOP
If it is helpful this is my senator.js file:
const senatorData = [
  {
    id: '1',
    firstName: 'Saud',
    lastName: 'Anwar',
    district: 'S03',
    yearElected: '',
    photoURL: 'http://www.senatedems.ct.gov/images/anwar-00prT.jpg',
    party: 'Democrat',
  },
  {
    id: '2',
    firstName: 'Eric',
    lastName: 'Berthel',
    district: 'S32',
    yearElected: '',
    photoURL:
      'https://ctsenaterepublicans.com/wp-content/uploads/2023/10/Untitled-design-1-1.jpg',
    party: 'Republican',
  },
  {
    id: '3',
    firstName: 'Jorge',
    lastName: 'Cabrera',
    district: 'S17',
    yearElected: '',
    photoURL:
  'http://www.senatedems.ct.gov/templates/Cabrera/images/Cabrera1x1.jpg',
    party: 'Democrat',
  },
  {
    id: '4',
    firstName: '',
    lastName: '',
    district: '',
    yearElected: '',
    photoURL: '',
    party: '',
  },
];
Rohu
did you export it in senator.js?
Answer
@Rohu did you export it in senator.js?
Cape lionOP
🤦🏽🤣 No... Thanks that did the trick. I appreciate the second set of eyes on this.