javascript - 当我使用 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
,但没有奏效
你有什么建议 ?
编辑
包.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"
}
解决方案
看起来 serve 包上的“-s”或“--single”参数/选项要么不工作,要么不再按预期工作,因此对“/”以外的路径的请求不会被重写。
查看 serve 包的以下问题:https ://github.com/zeit/serve/issues/525
在我的测试设置中,按照错误报告中的建议进行降级,解决了这个问题。
npm 卸载 -g 服务
npm install -g serve@10.1.1
服务 -s 构建
推荐阅读
- c# - 为序列化 c# 对象返回的 JSON 中计算机之间的差异
- html - 防止在图标转换期间调整按钮大小
- pandas - 将 Pandas 最佳拟合函数转换为 pyspark
- laravel - laravel 路由调用登台服务器上的 loalhost api 文件
- javascript - 在响应错误之前重试 async/await try and catch 块 3 次
- websocket - IBM Watson 语音到文本 API 中的 1006 错误代码
- video - FFmpeg Video is not shown, after encoding audio and video
- python - 在 TensorFlow 中使用 SciPy 函数:ValueError('invalid axis')
- linux - 如何执行matlab函数并将输出保存在linux的新文件中?
- java - 在这种情况下是否需要关闭 StringReader?