首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >直接导航到内部url时的React NextJS 502 BAD_GATEWAY

直接导航到内部url时的React NextJS 502 BAD_GATEWAY
EN

Stack Overflow用户
提问于 2020-07-05 22:24:18
回答 1查看 598关注 0票数 0

我有一个反应应用程序,使用NextJS我有很多内部链接到我的网页,所有的工作都很好

但是当我试图导航到网站而不是主页时,我收到消息"502 BAD_GATEWAY“

例如:导航此链接:https://power-tools.co.il/然后单击右侧第一个工具,您将成功导航到:https://power-tools.co.il/rentals/generators

但是如果您尝试直接导航到相同的url:https://power-tools.co.il/rentals/generators

你会得到错误:"502 BAD_GATEWAY“

为什么会出现这种情况,如何解决?

以下是生产环境中运行时错误的日志:

代码语言:javascript
复制
info  - Loaded env from .env.production
2020-07-06T07:20:37.771Z    undefined   ERROR   Uncaught Exception  {"errorType":"Error","errorMessage":"Must use import to load ES Module: /var/task/node_modules/flatted/cjs/index.js\nrequire() of ES modules is not supported.\nrequire() of /var/task/node_modules/flatted/cjs/index.js from /var/task/.next/serverless/pages/rentals/[categoryID].js is an ES module file as it is a .js file whose nearest parent package.json contains \"type\": \"module\" which defines all .js files in that package scope as ES modules.\nInstead rename index.js to end in .cjs, change the requiring code to use import(), or remove \"type\": \"module\" from /var/task/node_modules/flatted/package.json.\n","code":"ERR_REQUIRE_ESM","stack":["Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/task/node_modules/flatted/cjs/index.js","require() of ES modules is not supported.","require() of /var/task/node_modules/flatted/cjs/index.js from /var/task/.next/serverless/pages/rentals/[categoryID].js is an ES module file as it is a .js file whose nearest parent package.json contains \"type\": \"module\" which defines all .js files in that package scope as ES modules.","Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove \"type\": \"module\" from /var/task/node_modules/flatted/package.json.","","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1149:13)","    at Module.load (internal/modules/cjs/loader.js:977:32)","    at Function.Module._load (internal/modules/cjs/loader.js:877:14)","    at Module.require (internal/modules/cjs/loader.js:1019:19)","    at require (internal/modules/cjs/helpers.js:77:18)","    at Object.U3Ae (/var/task/.next/serverless/pages/rentals/[categoryID].js:1964:18)","    at __webpack_require__ (/var/task/.next/serverless/pages/rentals/[categoryID].js:23:31)","    at Object.C8l3 (/var/task/.next/serverless/pages/rentals/[categoryID].js:1306:25)","    at __webpack_require__ (/var/task/.next/serverless/pages/rentals/[categoryID].js:23:31)","    at Module.wN1p (/var/task/.next/serverless/pages/rentals/[categoryID].js:4487:30)"]}
Unknown application error occurred
Error
EN

回答 1

Stack Overflow用户

发布于 2020-07-05 23:42:55

因为这是React,所以我怀疑Web服务器没有正确处理应用程序路由。

作为一种可能的解决方案,您能否确保已在package.json中使用网站的URL值定义了"homepage"

代码语言:javascript
复制
"homepage": "https://power-tools.co.il/",

并尝试重新部署它吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62741935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档