问题
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.
- Download and install Git for Windows from here
- Run
npm cache clean
to clean npm cache - Run
npm install npm@latest -g
to install the latest version of npm - 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". 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"
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