404在React Production版本中找不到请求的路径

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

标签: node.js reactjs npm build production

我已经使用“ npm run build”构建了生产中的网站,并使用“ serve -s build”运行了网站,但是出现了以下错误。

ERROR: 404 The requested path cannot be found.

我相信,因为路径为静态形式,所以它们不是相对的,因此无法找到路径。 我已经看过一些解决方案,但对我却没有用。

我尝试过的解决方案:

通过放置此“首页”:”。在package.json文件中,但是没有用。

package.json

{
  "homepage" : ".",
  "name": "auth-api",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "alert-node": "^1.2.4",
    "bcrypt": "^3.0.5",
    "body-parser": "^1.18.3",
    "canvasjs": "^1.8.1",
    "cors": "^2.8.5",
    "express": "^4.16.4",
    "jsonwebtoken": "^8.5.1",
    "morgan": "^1.9.1",
    "nodemon": "^1.18.11",
    "oracledb": "^3.1.2",
    "password-hash": "^1.2.2"
  }
}

这是我的index.html文件:

<!doctype html><html lang="en">
    <head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=PT+Serif|Open+Sans:300,400,600,700,800">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"><link rel="manifest" href="/manifest.json"/>
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
    <link rel="manifest" href="/site.webmanifest">
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="theme-color" content="#ffffff">
    <title>eClaims</title>
    <link href="/static/css/2.cdbbd950.chunk.css" rel="stylesheet">
    <link href="/static/css/main.072676f8.chunk.css" rel="stylesheet"></head>
    <body>
        <noscript>You need to enable JavaScript to run this app.</noscript>
        <div id="root">

        </div>
        <script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={1:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])
        </script>
        <script src="/static/js/2.62ad15cb.chunk.js">
        </script>
        <script src="/static/js/main.d6a5f45a.chunk.js">
        </script>
        </body>
        </html>

0 个答案:

没有答案