在GitHub上反应应用程序部署失败

时间:2018-08-07 12:36:42

标签: reactjs

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

下面是我的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

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,在GitHub上部署react应用,并通过以下方法解决了该问题:

  1. 在项目文件夹git remote add origin <url>中运行命令,并使用Gi​​tHub上存储库的URL。
  2. 运行命令npm install --save-dev gh-pages
  3. 运行npm run build
  4. 运行命令npm run deploy
  5. 更改GitHub中部署的分支,请参见下图。在来源下必须为gh-pages branchenter 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

答案 1 :(得分:0)

最佳方法

git init

git remote add origin <repo_link>

yarn add gh-pages

yarn build

yarn deploy

现在转到您的Github并更新

Settings-->Github Pages-->source (change to gh-pages branch)-->root-->Save

,然后检查生成的链接/主页。

相关问题