首页 > 解决方案 > 无法在 Github 页面上部署新的 create-react-app

问题描述

刚刚完成了一个巨大的应用程序并试图将其部署在 github 上,但它开始抛出 404 错误。我试图创建一个新的,只对 HTML 进行一次更改(只是为了看到它是定制的),它抛出了同样的错误。开发版有效,生产版无效。

这是错误:

DevTools 无法加载 SourceMap:无法加载 chrome-> 扩展的内容://hgmhmanijnjhaffoampdlllchpolkdnj/js/lib/purify.min.js.map:HTTP 错误:状态码

404, net::ERR_UNKNOWN_URL_SCHEME favicon.ico:1 获取 https://kirilchristov.github.io/favicon.ico 404 manifest.json:1 获取 https://kirilchristov.github.io/manifest.json 404 manifest.json: 1 清单:行:1,列:1,语法错误。

这是回购的链接:Github Repo

这是带有脚本的 package.json:

{
  "home":"https://kirilchristov.github.io/renker",
  "name": "gr",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.3"
  },
  "scripts": {
    "predeploy": "npm run build",
    "deploy":"gh-pages -d build",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

标签: reactjsgithub

解决方案


您需要三件事让 CRA 处理 gh-pages

  1. 带有 prod 文件的分支(默认为gh-pages

    ✅ 你有那个(我检查过)

  2. 启用 gh-pages 的设置,如果不是默认设置,则选择分支并提供服务root

    ✅ 你也有,你说

  3. 你里面的homepage钥匙package.json

    ❌ 你有home而不是homepage https://create-react-app.dev/docs/deployment#building-for-relative-paths

尝试在你的package.json

{
  "homepage":"https://kirilchristov.github.io/renker",
  "name": "gr",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.3"
  },
  "scripts": {
    "predeploy": "npm run build",
    "deploy":"gh-pages -d build",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

推荐阅读