gpt4 book ai didi

reactjs - 在 github 上 React 应用部署失败

转载 作者:行者123 更新时间:2023-12-03 19:46:45 25 4
gpt4 key购买 nike

任何人都可以帮助我如何在 github 上部署我的 react 应用程序。我使用更新的 react 模块在我的 package.json 文件中添加了所有必需的依赖项。

下面是我的 package.json 文件:

    {
"name": "git-sample-react",
"version": "0.1.0",
"private": true,
"homepage": "https://ababsheck.github.io/first-react-sample/",
"dependencies": {
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-scripts": "1.1.4"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"deploy": "gh-pages -b master -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"gh-pages": "^1.2.0"
}
}

npm 运行部署问题:github
    Failed to get remote.origin.url (task must either be run in a git repository with a configured origin remote or must be configured with the "repo" option).
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! git-sample-react@0.1.0 deploy: `gh-pages -b master -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the git-sample-react@0.1.0 deploy 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\abhis\AppData\Roaming\npm-cache\_logs\2018-08-07T12_21_21_735Z-debug.log

最佳答案

我遇到了同样的问题,在 GitHub 中部署 react 应用程序并通过以下问题解决了这个问题:

  • 运行项目文件夹中的命令git remote add origin <url> ,以及您在 GitHub 上的存储库的 URL。
  • 运行命令npm install --save-dev gh-pages .
  • 运行 npm run build .
  • 运行命令npm run deploy .
  • 更改您部署的 GitHub 中的分支,请参见下图。在源下必须是 gh-pages branch .
    enter image description here

  • 我还添加了 "homepage": "https://ababsheck.github.io/first-react-sample/",
    在脚本之前,例如:
    "homepage": "https://ababsheck.github.io/first-react-sample/",
    "scripts": {
    "predeploy": "npm run build",
    ...// the rest of the code

    关于reactjs - 在 github 上 React 应用部署失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51726977/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com