最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

为什么git bash在npm安装gh

运维笔记admin14浏览0评论

为什么git bash在npm安装gh

为什么git bash在npm安装gh

我的问题

我正在尝试将GatsbyJS静态站点部署到我的GitHub页面索引页面,但是由于某些原因,终端/命令行无法将gh-pages识别为有效命令。我在vscode中使用git bash,但也尝试过Windows cmd。我希望当我运行添加到package.json的部署脚本时,该站点将发布到我的GitHub页面站点.github.io。我收到各种错误消息,但没有找到类似问题的充分答案。

我的设置

package.json

{
  "name": "gatsby-starter-dimension-v2",
  "description": "Gatsby Starter - Dimension V2",
  "version": "1.0.0",
  "author": "Hunter Chang",
  "dependencies": {
    "gatsby": "^2.0.76",
    "gatsby-plugin-manifest": "^2.0.24",
    "gatsby-plugin-offline": "^2.0.25",
    "gatsby-plugin-react-helmet": "^3.0.2",
    "gatsby-plugin-sass": "^2.0.7",
    "node-sass": "^4.11.0",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-helmet": "^5.2.0"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write '**/*.js'",
    "test": "echo \"Error: no test specified\" && exit 1",
    "deploy": "gatsby build && gh-pages -d public -b master"
  },
  "devDependencies": {
    "gh-pages": "^2.1.1",
    "prettier": "^1.14.2"
  },
  "repository": {
    "type": "git",
    "url": ""
  }
}

我尝试过的事情

在the Gatsby docs之后,我运行npm install gh-pages --save-dev,并向我的package.json文件中添加了自定义部署脚本:

`{
  "scripts": {
    "deploy": "gatsby build && gh-pages -d public -b master"
  }
}`

[添加该脚本后,我运行了npm run deploy。结果发布在此帖子的末尾。

gatsby build运行没有问题,所以我尝试运行gh-pages希望看到一些东西,但是它说找不到命令。

我找到this post并运行npm cache clean --force,删除了node_modulespackage-lock.json,然后再次运行npm install

我已经搜寻类似问题已有一段时间了。有任何想法吗?这是我的第一篇文章,请对我轻松一点...

终端输出(每个命令)

$ gh-pages
bash: gh-pages: command not found

$ gh-pages -d public -b master
bash: gh-pages: command not found

$ npm run deploy

`> [email protected] deploy C:\Users\Benjamin\Desktop\repos\personal-website-gatsby
> gatsby build && gh-pages -d public -b master
<various success messages, minor warnings, and info's>
...
...
fatal: HttpRequestException encountered.
   An error occurred while sending the request.
bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for '': No error

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] deploy: `gatsby build && gh-pages -d public -b master`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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\Benjamin\AppData\Roaming\npm-cache\_logs\2019-09-16T00_04_41_443Z-debug.log`

`Benjamin@DESKTOP-5T102UF MINGW64 ~/Desktop/repos/personal-website-gatsby (master)
$ npm install gh-pages --save-dev
npm notice save gh-pages is being moved from dependencies to devDependencies
npm WARN [email protected] requires a peer of [email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ [email protected]
updated 1 package and audited 20651 packages in 58.504s
found 0 vulnerabilities`
回答如下:

请参见https://www.npmjs/package/gh-pages#basic-usage

您需要做的是创建一个js脚本来使用该模块。我建议您在项目根目录下的scripts目录下创建它。

粘贴您需要运行的代码。我建议以下配置上传到公共目录:

ghpages.publish( 'public', { branch: 'master', repo: '', }, () => { console.log('Deploy Complete!') } )

输入您的回购属性。 =>定义输出到控制台的回调函数。

[下一步,打开项目目录根目录下的package.json。您将看到用默认的Gatsby脚本定义的“脚本”,您将需要添加一个脚本进行部署。

[在末尾添加以下内容:deploy:github": "npm run build && node ./scripts/deploy-github"

保存文件,执行npm run,您将看到可以执行的脚本列表。要部署时,请执行npm run deploy:github

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论