简体   繁体   English

React 应用程序在 localhost 上运行,但在 github 或 heroku 上部署时出错。 部署时没有错误

[英]React app working on localhost but giving error when deployed either on github or on heroku. No error while deploying

I create a react app to show corona infection in different countries.我创建了一个反应应用程序来显示不同国家的电晕感染。 This work on my localhost but when i deploy it either on github or on heroku a error generated.这在我的本地主机上工作,但是当我在 github 或 heroku 上部署它时,会生成一个错误。 below error is given in blockquote.以下错误在块引用中给出。 Looking at error when i check file country.js there is no n[0] .当我检查文件country.js时查看错误,没有n[0] please help below is link to hosted app and github repository of the app.请帮助下面是托管应用程序和应用程序的github存储库的链接。

TypeError: "n[0] is undefined" E country.js:13 E country.js:11 React 7 unstable_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 react-dom.production.min.js:209:194 React 5 unstable_runWithPriority scheduler.production.min.js:19 React 4 unstable_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] is undefined country.js:13:30 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 a asyncToGenerator.js:25 react-dom.production.min.js:209:194 React 5unstable_runWithPriority scheduler.production.min.js:19 React 4unstable_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

this is link to hosted app on heroku and this is link to app hosted on Github这是在Heroku链接托管应用这是链接到托管在Github上的应用

This is github repository这是 github 存储库

As stated by Dishant Desai , it is giving a TypeError.正如Dishant Desai 所说,它给出了一个类型错误。 In order to fix it, you can change the code in country.js from为了修复它,您可以将country.js的代码从

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

to

const countryflag = data[0];

And use it directly this way:并以这种方式直接使用它:

${countryflag[country[0]]}

I have checked your site and it gives the following error:我检查了你的网站,它给出了以下错误:

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

So for that, you have to share the code of that file.因此,为此,您必须共享该文件的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM