【问题标题】:Deploying React App to Git Hub Pages failed将 React 应用程序部署到 Github 页面失败
【发布时间】:2026-02-13 05:40:01
【问题描述】:

我正在尝试将我的 react 应用程序部署到 github 页面............

按照教程并设法使其适用于以前的项目。 当我运行 npm run deploy 我收到此错误 任何帮助将不胜感激如何解释此错误 我尝试了在这里找到的不同解决方案,但没有任何帮助

npm 运行部署

> Neighbourhood-Map-React@0.1.0 predeploy C:\Users\mels_\Documents\Neighbourhood-Map-React
> npm run build


> Neighbourhood-Map-React@0.1.0 build C:\Users\mels_\Documents\Neighbourhood-Map-React
> react-scripts build

   Creating an optimized production build...
   Failed to compile.

   Error: Parse Error: <meta name="viewport" content="width=device-width, initial  
     -scale=1>
      <meta name="theme-color" content="#000000">
      <!--
        manifest.json provides metadata used when your web app is added to the
        homescreen on Android. See https://developers.google.com/web/fundamental  
      s/engage-and-retain/web-app-manifest/
      -->
      <link rel="manifest" href="/github.io/Neighbourhood-Map-React/manifest.jso  n">
      <link rel="shortcut icon" href="/github.io/Neighbourhood-Map-React/favicon  .ico">
      <!--
        Notice the use of /github.io/Neighbourhood-Map-React in the tags above.
        It will be replaced with the URL of the `public` folder during the build  .
        Only files inside the `public` folder can be referenced from the HTML.
        Unlike "/favicon.ico" or "favicon.ico", "/github.io/Neighbourhood-Map-Re  act/favicon.ico" will
        work correctly both with client-side routing and a non-root public URL.
        Learn how to configure a non-root public URL by running `npm run build`.      -->
      <title>React App</title>
    <link href="/github.io/Neighbourhood-Map-React/static/css/main.c066d278.css"   rel="stylesheet"></head>
    <body>
      <noscript>
        You need to enable JavaScript to run this app.
      </noscript>
      <div id="root"></div>
      <!--
        This HTML file is a template.
        If you open it directly in the browser, you will see an empty page.
        You can add webfonts, meta tags, or analytics to this file.
        The build step will place the bundled scripts into the <body> tag.
        To begin the development, run `npm start` or `yarn start`.
        To create a production bundle, use `npm run build` or `yarn build`.
      -->
    <script type="text/javascript" src="/github.io/Neighbourhood-Map-React/stati  c/js/main.df359430.js"></script></body>
  </html>

  - htmlparser.js:240 new HTMLParser
    [Neighbourhood-Map-React]/[html-minifier]/src/htmlparser.js:240:13

  - htmlminifier.js:951 minify
    [Neighbourhood-Map-React]/[html-minifier]/src/htmlminifier.js:951:3

  - htmlminifier.js:1306 exports.minify
    [Neighbourhood-Map-React]/[html-minifier]/src/htmlminifier.js:1306:16

  - index.js:296
    [Neighbourhood-Map-React]/[html-webpack-plugin]/index.js:296:16

  - util.js:16 tryCatcher
    [Neighbourhood-Map-React]/[bluebird]/js/release/util.js:16:23

  - promise.js:512 Promise._settlePromiseFromHandler
    [Neighbourhood-Map-React]/[bluebird]/js/release/promise.js:512:31

  - promise.js:569 Promise._settlePromise
    [Neighbourhood-Map-React]/[bluebird]/js/release/promise.js:569:18

  - promise.js:614 Promise._settlePromise0
    [Neighbourhood-Map-React]/[bluebird]/js/release/promise.js:614:10

  - promise.js:693 Promise._settlePromises
    [Neighbourhood-Map-React]/[bluebird]/js/release/promise.js:693:18

  - async.js:133 Async._drainQueue
    [Neighbourhood-Map-React]/[bluebird]/js/release/async.js:133:16

  - async.js:143 Async._drainQueues
    [Neighbourhood-Map-React]/[bluebird]/js/release/async.js:143:10

  - async.js:17 Immediate.Async.drainQueues [as _onImmediate]
    [Neighbourhood-Map-React]/[bluebird]/js/release/async.js:17:14


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Neighbourhood-Map-React@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Neighbourhood-Map-React@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\mels_\AppData\Roaming\npm-cache\_logs\2018-07-20T13_00_54_457Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Neighbourhood-Map-React@0.1.0 predeploy: `npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Neighbourhood-Map-React@0.1.0 predeploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\mels_\AppData\Roaming\npm-cache\_logs\2018-07-20T13_00_54_550Z-debug.log
warning: LF will be replaced by CRLF in package-lock.json.
The file will have its original line endings in your working directory.

【问题讨论】:

  • 好像你忘记了 " 在 initial-scale=1 之后,应该是

标签: reactjs github-pages create-react-app


【解决方案1】:

正如@Orkhan Jafarov 指出的那样,您的脚本在解析错误时失败。您在meta 标签的末尾缺少"

   Error: Parse Error: <meta name="viewport" content="width=device-width, initial-scale=1>

【讨论】:

  • oooppsss 我现在感到很尴尬。我花了一整天的不同尝试。由于本地主机工作,我没有检查那部分,所以我认为问题出在其他地方。感谢您的帮助和时间。非常感谢
【解决方案2】:

在 Git 中使用 HTTPS 时会出现一些常见错误。这些错误通常表明您拥有旧版本的 Git,或者您无权访问存储库。 当系统提示您输入用户名和密码时,请确保您使用的帐户可以访问存储库。

使用适用于 Windows 的 Git,在命令行中运行以下命令将存储您的凭据:

$ git config --global credential.helper wincred

这称为开启密码缓存

【讨论】: