React App生产版本显示JS错误 [英] React app production build shows js errors

查看:101
本文介绍了React App生产版本显示JS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 create-react-app 创建了一个客户端react应用程序.它与运行Express API的节点服务器通信.在开发中,一切工作都很好,并且已经准备好进行部署.

I've created a client react application using create-react-app. It talks to a node server running an express api. In development everything is working great and was getting ready to deploy.

当运行 npm run build 时,我也没有任何错误,一切似乎都很好.构建完成后,建议运行 serve -s build ,然后执行此操作并导航到我的本地主机:5000,显示我应用程序中的第一个console.logs,但随后突然抛出一个看似简单的javascript错误:

When running npm run build I get no errors whatsoever either, everything seems to be working great. When build finishes it suggest to run serve -s build , I do this and navigate to my localhost:5000, the first console.logs from my app show up but then suddenly i throws a seemingly simple javascript error:

TypeError: "e.forEach is not a function"
    me InboundTab.js:27
    me InboundTab.js:36
    React 7
    unstable_runWithPriority scheduler.production.min.js:270
    React 5
    getArrivals ArrivalState.js:39
    l runtime.js:45
    _invoke runtime.js:264
    t runtime.js:98
    l runtime.js:45
    t runtime.js:137
    t runtime.js:147
react-dom.production.min.js:4636:12
    React 5
    unstable_runWithPriority scheduler.production.min.js:270
    React 4
    unstable_runWithPriority scheduler.production.min.js:270
    React 5
    getArrivals ArrivalState.js:39
    l runtime.js:45
    _invoke runtime.js:264
    t runtime.js:98
    l runtime.js:45
    t runtime.js:137
    t runtime.js:147

我一直在互联网上寻找信息,但是找不到关于这里发生情况的任何线索.大多数网站都在谈论构建过程中的错误,或者一个网站根本不显示,但这都不是.谷歌搜索错误似乎表明这是一些ES6问题,但是我正在运行firefox 73,所以我希望在这方面没有问题.

I've been looking all over the internet but can't find any clues on what's going on here. Most sites talk about errors during the build process or a site not showing at all but this is neither. Googling the error seems to say this is some ES6 issue, but I'm running firefox 73 so I'd expect no issues on that front.

作为额外的信息,这是我第一次尝试部署React.有趣的是,到目前为止,我只做过一些在本地运行的小项目,所以我很确定自己在构建过程中缺少明显的东西.

As extra info this is my first time trying to deploy react. Funny enough I'd only done small projects so far running locally so I am pretty sure I'm missing something obvious in the build process.

任何帮助,最感谢您在哪里循环的提示.谢谢!

Any help, tips on where to loop will be most appreciated. Thanks!

推荐答案

回答我自己的问题.我想我只需要重新阅读该错误并以语法突出显示,因为文件名和行位置将我带到了正确的位置.

Answering my own question. I guess I just needed to re-read this error with the nice syntax highlight because the filename and line location took me to the right place.

在客户端的api调用中,我将服务器网址设置为:

On my client's api calls I set up the server url as:

const API_SERVER =
  process.env.NODE_ENV === "development"
    ? "http://localhost:4200"
    : "http://example.com";

但是我的example.com尚未设置,因此错误来自无法访问服务器.将example.com更改为localhost并重新构建后,一切正常.

but my example.com isn't setup yet so the error came from not being able to reach the server. Changing the example.com to localhost and re-building made things work.

这篇关于React App生产版本显示JS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆