【问题标题】:React app working on localhost but giving error when deployed either on github or on heroku. No error while deployingReact 应用程序在 localhost 上运行,但在 github 或 heroku 上部署时出错。部署时没有错误
【发布时间】:2020-07-10 11:07:05
【问题描述】:

我创建了一个反应应用程序来显示不同国家/地区的电晕感染情况。这在我的本地主机上工作,但是当我在 github 或 heroku 上部署它时,会产生错误。以下错误在块引用中给出。当我检查文件 country.js 时查看错误,没有 n[0]。请帮助下面是托管应用程序和应用程序 github 存储库的链接。

类型错误:“n[0] 未定义” E 国家.js:13 E 国家.js:11 反应 7 不稳定的runWithPriority scheduler.production.min.js:19 反应 6 一个 App.js:22 你 runtime.js:45 _invoke runtime.js:274 t runtime.js:97 r asyncToGenerator.js:3 asyncToGenerator.js:25 反应-dom.production.min.js:209:194 反应 5 不稳定的runWithPriority scheduler.production.min.js:19 反应 4 不稳定的runWithPriority scheduler.production.min.js:19 反应 6 一个 App.js:22 你 runtime.js:45 _invoke runtime.js:274 t runtime.js:97 r asyncToGenerator.js:3 asyncToGenerator.js:25 类型错误:n[0] 未定义 country.js:13:30

​ this is link to hosted app on heroku 和 this is link to app hosted on Github

This is github repository

【问题讨论】:

  • 错误 - 无法读取未定义的属性“阿富汗”。 Country.js 第 13 行

标签: reactjs heroku web-deployment


【解决方案1】:

我检查了您的网站,它给出了以下错误:

react_devtools_backend.js:6 TypeError: Cannot read property 'Afghanistan' of undefined
    at country.js:13
    at Array.map (<anonymous>)
    at E (country.js:11)
    at Ki (react-dom.production.min.js:153)
    at Fo (react-dom.production.min.js:175)
    at va (react-dom.production.min.js:263)
    at cu (react-dom.production.min.js:246)
    at au (react-dom.production.min.js:246)
    at Za (react-dom.production.min.js:239)
    at react-dom.production.min.js:123

因此,您必须共享该文件的代码。

【讨论】:

【解决方案2】:

作为stated by Dishant Desai,它给出了一个TypeError。为了修复它, 您可以从

更改country.js 中的代码
const countryflag = Object.keys(data).map((name) => {
    return data[name][0];
})

到

const countryflag = data[0];

并直接这样使用:

${countryflag[country[0]]}

【讨论】:

    猜你喜欢
    • 2022-07-15
    • 2022-06-29
    • 2021-03-25
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 2020-12-09
    相关资源
    最近更新 更多