首页 > 解决方案 > React 应用程序在 localhost 上运行,但在 github 或 heroku 上部署时出错。部署时没有错误

问题描述

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

TypeError: "n[0] is undefined" E country.js:13 E country.js:11 React 7 stable_runWithPriority scheduler.production.min.js:19 React 6 a App.js:22 u runtime.js:45 _invoke runtime .js:274 t runtime.js:97 r asyncToGenerator.js:3 aasyncToGenerator.js:25 react-dom.production.min.js:209:194 React 5不稳定_runWithPriority scheduler.production.min.js:19 React 4不稳定_runWithPriority scheduler.production.min.js:19 React 6 a App.js:22 u runtime.js:45 _invoke runtime.js:274 t runtime.js:97 r asyncToGenerator.js:3 a asyncToGenerator.js:25 TypeError: n [0] 未定义 country.js:13:30

是指向 Heroku 上托管应用程序的链接 , 这是指向 Github上托管应用程序的链接

这是 github 存储库

标签: reactjsherokuweb-deployment

解决方案


正如Dishant Desai 所说,它给出了一个 TypeError。为了修复它,您可以将代码更改country.js

const countryflag = Object.keys(data).map((name) => {
    return data[name][0];
})

const countryflag = data[0];

并以这种方式直接使用它:

${countryflag[country[0]]}

推荐阅读