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

时间:2019-04-25 11:31:31

标签: javascript reactjs dev-to-production

我已经用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"
}

1 个答案:

答案 0 :(得分:0)

服务包上的“ -s”或“ --single”自变量/选项似乎无法正常工作或不再按预期工作,因此不会重写对除“ /”以外的路径的请求。

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

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

npm卸载-g服务

npm install -g serve@10.1.1

提供-s build