当我使用 react.js 投入生产时出错

Error when i go into production with react.js

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

我做到了

npm run build

serve -s build 

我继续localhost:5000

欢迎页面运行良好,但是当我继续localhost:5000/main我有一个错误

404 | The requested path could not be found

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

你有什么建议?

编辑

Package.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"
}

似乎服务包上的“-s”或“--single”argument/option 无法正常工作或不再按预期工作,因此对“/”以外的路径的请求未被处理重写。

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

在我的测试设置中,按照错误报告中的建议降级服务解决了这个问题。

npm uninstall -g serve

npm install -g serve@10.1.1

服务-s 构建