在开发模式下运行良好时,在构建NextJS应用程序的构建时获取404页

发布于 2025-01-27 22:18:20 字数 836 浏览 2 评论 0原文

我对反应/下一个JS是很新的。所以这是我的问题。我已经购买了一个主题,并更改了配置和品牌部分。现在,当我使用“ Yarn Dev”和“ Yarn Start”运行该应用程序时,它正常工作。 “纱线构建”还创建了优化的生产构建。我想在我的PC上本地部署该应用程序,并且试图通过YouTube视频来学习内容。因此,在其中一个视频中,我找到了此命令(“ prod”:“下一个构建&& serve build build”),以包含在package.json中。我的poffage.json文件具有以下脚本。

“脚本”:{ “ dev”:“ Next Dev”, “构建”:“下一个构建”, “开始”:“下一个开始”, “导出”:“ Next Export”, “ lint”:“ eslint -fix” src//*。{js,jsx}“”, “格式”:“ Prettier -write” Src//*。{JS,JSX}“”, “ prod”:“下一个构建&& serve build'' },

因此,当我尝试使用“纱线产品”时,它首先创建了优化的构建,然后在VSCODE终端中获得以下输出

“

但是,如果我尝试打开“ http:// localhost) :3000英寸在我的浏览器中。我有404错误。但不是使用“纱线开发”或“纱线开始”。构建应用程序时也没有错误。

I am pretty new to React/Next JS. So here's my issue. I have purchased a theme and made changes to the config and branding part. Now when I run the app using "yarn dev" and "yarn start", it is working fine. "yarn build" also creates an optimized production build. I wanted to deploy the app locally in my PC and i was trying to learn things through youtube videos. so in one of the videos i found this command ("prod": "next build && serve build") to include in package.json. my package.json file has the following scripts.

"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"export": "next export",
"lint": "eslint --fix "src//*.{js,jsx}"",
"format": "prettier --write "src/
/*.{js,jsx}"",
"prod": "next build && serve build"
},

so when i try with "yarn prod", it is first creating an optimized build and then i get the following output in the vscode terminal

enter image description here

however if i try to open "http://localhost:3000" in my browser. i get 404 error. but not with "yarn dev" or "yarn start". no error while building the app too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单挑你×的.吻 2025-02-03 22:18:20

添加“ cleanurls”:true 到“ firebase.json”文件,如下

 {
  "hosting": {
    "public": "out",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "cleanUrls": true,
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

Add the "cleanUrls": true to "firebase.json" file as below

 {
  "hosting": {
    "public": "out",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "cleanUrls": true,
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文