【问题标题】:Syntax error: Cannot read property 'map' of undefined (0:undefined) build on aws amplify语法错误:无法读取基于 aws amplify 构建的未定义(0:未定义)的属性“地图”
【发布时间】:2020-12-18 01:38:14
【问题描述】:

在 AWS amplify 上构建时遇到以下错误:

语法错误:无法读取未定义的属性“地图”(0:未定义)

这是我的代码:

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>

【问题讨论】:

标签: reactjs


【解决方案1】:

我在 AWS Amplify 控制台上构建失败时遇到了同样的问题,但在本地很好。

如何在本地复现

我可以按照以下步骤在本地重现它:

  1. 运行“npm ci”
  2. 运行“npm start”

“npm start”会失败,并显示错误“Line 0: Parsing error: Cannot read property 'map' of undefined”。

如何解决

我最终通过以下步骤解决了这个问题:

  1. 将 typescript 从 4.0.2 版降级到 3.9.7 版。
  2. 运行“npm ci”
  3. 运行“npm start”

我不再看到错误,当我推送到 AWS Amplify 控制台时,它的构建没有问题。

【讨论】:

  • 这对我有帮助,即使我不使用 AWS Amplify。 TS 编译器和 babel/webpack 似乎有问题。
【解决方案2】:

我对这段代码有类似的问题:

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

当我指定数组的类型时问题就消失了:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-01
    • 2014-09-02
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多