Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 为什么赢了';在npm安装gh页面后,git bash是否将gh页面识别为有效命令?[盖茨比JS,GitHub页面]_Node.js_Bash_Npm_Github Pages_Gatsby - Fatal编程技术网

Node.js 为什么赢了';在npm安装gh页面后,git bash是否将gh页面识别为有效命令?[盖茨比JS,GitHub页面]

Node.js 为什么赢了';在npm安装gh页面后,git bash是否将gh页面识别为有效命令?[盖茨比JS,GitHub页面],node.js,bash,npm,github-pages,gatsby,Node.js,Bash,Npm,Github Pages,Gatsby,我的问题 我正在尝试将GatsbyJS静态站点部署到我的GitHub pages索引页面,但由于某些原因,终端/命令行无法将gh pages识别为有效命令。我在vscode中使用gitbash,但也尝试过windowscmd。我希望当我运行添加到package.json的部署脚本时,该站点将发布到我的GitHub页面站点.GitHub.io。我收到了各种各样的错误消息,还没有找到足够的答案来解决类似的问题 我的设置 package.json: { "name": "gatsby-starte

我的问题

我正在尝试将GatsbyJS静态站点部署到我的GitHub pages索引页面,但由于某些原因,终端/命令行无法将
gh pages
识别为有效命令。我在vscode中使用gitbash,但也尝试过windowscmd。我希望当我运行添加到
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": "https://github.com/gatsbyjs/gatsby-starter-default"
  }
}
我尝试过的

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

$ gh-pages -d public -b master
bash: gh-pages: command not found
接下来,我运行了
npm install gh pages--save dev
,并在我的
package.json
文件中添加了一个自定义部署脚本:

`{
  "scripts": {
    "deploy": "gatsby build && gh-pages -d public -b master"
  }
}`
添加该脚本后,我运行了
npm run deploy
。结果发布在本帖末尾

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

我找到并运行了
npm缓存clean--force
,删除了
node\u模块
package lock.json
,然后再次运行了
npm安装

我已经四处寻找类似的问题有一段时间了。有什么想法吗?这是我在这里的第一篇帖子,请对我放松

终端输出(每个命令)

$npm运行部署

`> gatsby-starter-dimension-v2@1.0.0 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 'https://github.com': No error

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gatsby-starter-dimension-v2@1.0.0 deploy: `gatsby build && gh-pages -d public -b master`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gatsby-starter-dimension-v2@1.0.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\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 eslint-config-react-app@4.0.1 requires a peer of eslint-plugin-flowtype@2.x but none is installed. You must install peer dependencies yourself.
npm WARN ts-pnp@1.1.4 requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.17.1 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: fsevents@2.0.7 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.0.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ gh-pages@2.1.1
updated 1 package and audited 20651 packages in 58.504s
found 0 vulnerabilities`
盖茨比起动机尺寸-v2@1.0.0部署C:\Users\Benjamin\Desktop\repos\personal website gatsby >盖茨比建筑和gh页面-d公共-b主控 看

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

粘贴需要运行的代码。我建议使用以下方法配置上载到公用目录:

ghpages.publish(
"公众",,
{
分行:'主',
回购协议:,
},
() => {
console.log('Deploy Complete!')
}
)

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

接下来,在项目目录的根目录下打开package.json。您将看到使用默认Gatsby脚本定义的“脚本”,您需要为部署添加一个脚本

在末尾添加以下内容:
deploy:github:“npm运行构建和节点。/scripts/deploy github”

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