运行生产版本时 React App 崩溃 [英] React App crashes when running the production build

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

问题描述

我可以在本地开发服务器上完美地运行我的 react-app(使用 create-react-app 样板),但是当我使用 npm run build 编译它然后运行它时一个服务器(我尝试过 netlify 和本地 http-server),我只收到这个错误并且页面没有加载:

I can run my react-app (with the create-react-app boilerplate) perfectly fine with the local dev-server, but when I compile it using npm run build and then run it with a server (I tried netlify and local http-server), I do only get this error and the page does not load:

classCallCheck.js:1 Uncaught RangeError: Maximum call stack size exceeded
    at Object.a (classCallCheck.js:1)
    at e (Object.js:6)
    at e (Object.js:6)
    at e (Object.js:6)
    at e (Object.js:6)
    at e (Object.js:6)
    at e (Object.js:6)
    at e (Object.js:6)
    at e (Object.js:6)
    at e (Object.js:6)

Object.js 文件放在 src/Model/Objects/Object.js 下.

The file Object.js is placed under src/Model/Objects/Object.js.

GitHub:https://github.com/Tracer1337/DynaSys
在 Netlify 上部署:https://youthful-mestorf-9e0ba8.netlify.com/

我做错了什么?

推荐答案

这是一个有趣的调试方案.您似乎创建了一个名为 Object 的类,它是 JavaScript 中的受保护词.

That was an interesting one to debug. It seems like you have created a class called Object, which is a protected word in JavaScript.

您可以通过单击错误右侧的源来找出导致问题的原因.这将打开导致错误的相应文件(create-react-app 默认提供源映射,因此即使在生产中调试也不是问题).

You can figure out what is causing the issue by clicking on the source on the right hand side of the error. This will open the corresponding file that is causing the error (create-react-app provides source maps by default, so debugging even in production is not an issue).

我通过将 Object 类重命名为 InternalObject 解决了这个问题,现在即使在生产模式下也能正常运行!

I solved the issue by renaming the Object class to InternalObject, now everything runs fine even in production mode!

至于为什么它可以在具有该受保护名称的开发模式下工作,我不知道.也许其他人有想法?

As to why it does work in development mode with that protected name, I have no clue though. Maybe someone else has an idea?

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

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