gh-pagesでnpm run deployすると「fatal: could not read Username for 'https://github.com': Invalid argument」というエラーが出る


あらすじ

skytomo221.github.io にGatsbyでポートフォリオを作ろうと思って、
ここのサイトを参考に、gh-pagesを使ってnpm run deployしようとしたところ、「fatal: could not read Username for 'https://github.com': Invalid argument」というエラーが出た。

どんな感じでエラーが出たか

$ npm run deploy

> [email protected] deploy D:\skytomo\skytomo221.github.io
> gatsby build && gh-pages -d public -b master

success open and validate gatsby-configs - 0.160s
success load plugins - 1.500s
...(省略)...
Generated public/sw.js, which will precache 9 files, totaling 317400 bytes.
success onPostBuild - 0.554s
info Done building in 31.231 sec
Fatal: HttpRequestException encountered.
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': Invalid argument

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.
...(以下略)

色なしだと分かりにくいかもなので画像バージョンも

対処法

GitHub PagesにReactアプリをデプロイする方法に書かれていた解決方法

$ rm -rf node_modules
$ npm install
$ npm run deploy

上記の方法で解決できない場合、さらに、

git config --global credential.helper wincred

をしてみましょう。
fatal: could not read Username for 'https://github.com': No error #230に書かれていた方法です。
私はこれで解決しました。