使用react.js进入生产时出错

问题描述 投票:0回答:1

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

我做到了

npm run build

serve -s build 

我继续localhost:5000

欢迎页面效果很好,但是当我继续使用localhost:5000/maini时出错

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"
}
javascript reactjs dev-to-production
1个回答
1
投票

看起来服务包上的“-s”或“--single”参数/选项要么不起作用,要么不再按预期工作,因此对“/”以外的路径的请求不会被重写。

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

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

npm uninstall -g serve

npm install -g [email protected]

服务 - 建设

© www.soinside.com 2019 - 2024. All rights reserved.