Harish
Harish

Reputation: 121

Syntax error: Cannot read property 'map' of undefined (0:undefined) build on aws amplify

I am facing the following error while building on AWS amplify:

Syntax error: Cannot read property 'map' of undefined (0:undefined)

Here is my code:

import React from 'react';   
import ReactDOM from 'react-dom'; 
export default class BusinessHTTPService {
static getBusinessList = () => {
  
    return axios.get(`${API_BASE}business-categories/?`).then(response => response.data);
  };
  
  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

Upvotes: 10

Views: 2919

Answers (2)

Monsignor
Monsignor

Reputation: 2965

I had similar issue with this code:

interface Event<EventArgs extends unknown[] = []> { ... }

The problem disappeared when I specified the type of the array:

interface Event<EventArgs extends unknown[] = unknown[]> { ... }

Upvotes: 0

Enrico Pangan
Enrico Pangan

Reputation: 76

I had the same issue with by build failing on AWS Amplify Console, but was fine locally.

How to reproduce locally

I was able to reproduce it locally by following these steps:

  1. run "npm ci"
  2. run "npm start"

"npm start" would fail, and show the error "Line 0: Parsing error: Cannot read property 'map' of undefined".

How to solve

I was able to solve it eventually by following these steps:

  1. downgrade typescript from version 4.0.2 to version 3.9.7.
  2. run "npm ci"
  3. run "npm start"

I don't see the error anymore, and when I push to AWS Amplify Console, it builds without issues.

Upvotes: 5

Related Questions