【问题标题】:Error when i go into production with react.js当我使用 react.js 投入生产时出错
【发布时间】:2019-09-14 19:51:01
【问题描述】:

我用 react.js 创建了一个应用程序。我想投入生产。

我做到了

npm run build

serve -s build 

我继续localhost:5000

欢迎页面效果很好,但是当我继续localhost:5000/main时出现错误

404 | The requested path could not be found

我尝试重做npm run build,但没有成功

你有什么建议?

编辑

包.json

{
  "name": "name-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "firebase": "^5.10.0",
    "node-sass": "^4.11.0",
    "p5": "^0.8.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-p5-wrapper": "0.0.4",
    "react-router-dom": "^5.0.0",
    "react-scripts": "2.1.8",
    "socket.io-client": "^2.2.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "description": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).",
  "main": "index.js",
  "devDependencies": {},
  "author": "",
  "license": "ISC"
}

【问题讨论】:

  • 请分享 run build 的 package.json 规格同时在 chrome 开发人员工具上检查引发错误的 url,也许你没有指向 /build/
  • 我添加了package.json,chrome开发者没有错误
  • 你是否在你的 react 应用中为“/main”设置了路由?您是否期望“/main”会加载 index.js?
  • 在投入生产之前一切正常,但在 npm run build 之后它就不再工作了

标签: javascript reactjs dev-to-production


【解决方案1】:

似乎 serve 包上的“-s”或“--single”参数/选项无法正常工作或不再按预期工作,因此对“/”以外路径的请求不会被重写。

看一下 serve 包的以下问题:https://github.com/zeit/serve/issues/525

在我的测试设置中,按照错误报告中的建议进行降级,修复了该问题。

npm 卸载 -g 服务

npm install -g serve@10.1.1

服务 -s 构建

【讨论】:

  • 但是当我使用 filezila 在网上上传我的文件时,我有这个错误:未找到请求的 URL /main 在此服务器上未找到。主页工作
  • 您没有提供足够的信息。用filezilla上传到网上……上传到什么地方?您是在 Web 或应用服务器上托管它吗?什么类型和版本的服务器?您是否具有对服务器的命令行访问权限?如果服务器最终运行的是 npm serve,安装的是什么版本的 serve 包?如果您托管在 apache 或其他一些应用服务器上,是否配置了 URL 重写?
猜你喜欢
  • 1970-01-01
  • 2015-05-24
  • 2013-04-24
  • 2019-12-16
  • 1970-01-01
  • 2023-01-17
  • 1970-01-01
  • 1970-01-01
  • 2021-09-06
相关资源
最近更新 更多