10

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>
Dan Getz
  • 8,774
  • 6
  • 30
  • 64
Harish
  • 121
  • 1
  • 7
  • While I am building code on AWS it's throwing an error but locally when I am running the code its working fine. – Harish Aug 29 '20 at 09:30
  • Does this answer your question? [Line 0: Parsing error: Cannot read property 'map' of undefined](https://stackoverflow.com/questions/62079477/line-0-parsing-error-cannot-read-property-map-of-undefined) – smac89 Jul 06 '21 at 20:37

2 Answers2

5

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

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[]> { ... }
Monsignor
  • 2,671
  • 1
  • 36
  • 34