gh-pages failing while trying to deploy Reactjs app to GitHub in windows 10

纵然是瞬间 提交于 2019-12-12 02:33:44

问题


I tried following the exact instructions listed in the react documentation on how to deploy a working app to github pages. When I ran npm run deploy. It kept failing at the gh-pages -d build saying that the 'gh-pages' is not an internal or external command. I made sure I had the latest versions of node and npm installed

I had installed gh-pages using the -g tag to make it globally available. Tried adding to the system path variable leading to the node modules folder where i knew gh-pages was loaded. Still nothing.

Finally i tried running it from the git bash window instead of the cmd terminal. This hadn't occurred to me at first as all of the other npm commands worked. Don't know why this fixed things but it did. Just posting this so somebody else might be spared the pain


回答1:


I had the same issue but finally managed to make it work. The main issue was that I hadn't installed Git for Windows, but I took some extra steps to make sure everything works fine.

  1. Download and install Git for Windows from here
  2. Run npm cache clean to clean npm cache
  3. Run npm install npm@latest -g to install the latest version of npm
  4. Add "homepage" : "http://myname.github.io/myapp", to "package.json" file and replace the URL with correct GitHub pages URL. If you are not sure about the URL, open the project repository in the browser and go to "Settings" tab. Scroll down and find correct URL under "GitHub Pages".
  5. Run npm install --save-dev gh-pages to install gh-pages module Add the following 2 lines to "scripts" object in "package.json" file:

    "predeploy": "npm run build",

    "deploy": "gh-pages -d build"

  6. Finally, run npm run deploy to create an optimized production build and deploy it on GitHub pages. If you haven't logged in to Github for windows app before, Github app pops up and asks you to enter your username and password. When you've done that the deploy process will continue and uploads the production build on GitHub pages. Hope that helps, happy coding.




回答2:


If it says this, then node_modules/.bin/gh-pages doesn't exist (no, you don't need to install it globally). If it doesn't exist, then it means you either forgot to run npm install --save-dev gh-pages, or something went wrong during the installation.

I would not recommend installing it globally (although looks like it worked in your case).



来源:https://stackoverflow.com/questions/43150250/gh-pages-failing-while-trying-to-deploy-reactjs-app-to-github-in-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!