问题
Hey I have literally been trying this for days, I have went over documentation all over, I followed tutorials and I cannot get past npm run deploy when trying to deploy my react app to github pages. I call npm run build, I place the correct url to package.json as the 'homepage', i call it again and get the 'deploy' and 'predeploy', I definitely have gh-pages in node modules, I mean I got it all I have followed every step that every tutorial could have told me. I have ran into an issue that reads the following:
error: cannot spawn sh: No such file or directory fatal: unable to fork
npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! carlos_valencia_portfolio@0.1.0 deploy:
gh-pages -d build
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the carlos_valencia_portfolio@0.1.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\Carlos\AppData\Roaming\npm-cache_logs\2018-10-04T19_57_57_731Z-debug.log
Here are the contents of the log:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'deploy' ]
2 info using npm@6.2.0
3 info using node@v10.8.0
4 verbose run-script [ 'predeploy', 'deploy', 'postdeploy' ]
5 info lifecycle carlos_valencia_portfolio@0.1.0~predeploy: carlos_valencia_portfolio@0.1.0
6 verbose lifecycle carlos_valencia_portfolio@0.1.0~predeploy: unsafe-perm in lifecycle true
7 verbose lifecycle carlos_valencia_portfolio@0.1.0~predeploy: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Carlos\ReactJSProjects\carlos_valencia_portfolio\node_modules.bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Users\Carlos\AppData\Local\Microsoft\WindowsApps;C:\Users\Carlos\AppData\Roaming\npm;C:\Users\Carlos\AppData\Local\atom\bin;C:\Users\Carlos\AppData\Local\GitHubDesktop\bin
8 verbose lifecycle carlos_valencia_portfolio@0.1.0~predeploy: CWD: C:\Users\Carlos\ReactJSProjects\carlos_valencia_portfolio
9 silly lifecycle carlos_valencia_portfolio@0.1.0~predeploy: Args: [ '/d /s /c', 'npm run build' ]
10 silly lifecycle carlos_valencia_portfolio@0.1.0~predeploy: Returned: code: 0 signal: null
11 info lifecycle carlos_valencia_portfolio@0.1.0~deploy: carlos_valencia_portfolio@0.1.0
12 verbose lifecycle carlos_valencia_portfolio@0.1.0~deploy: unsafe-perm in lifecycle true
13 verbose lifecycle carlos_valencia_portfolio@0.1.0~deploy: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Carlos\ReactJSProjects\carlos_valencia_portfolio\node_modules.bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Users\Carlos\AppData\Local\Microsoft\WindowsApps;C:\Users\Carlos\AppData\Roaming\npm;C:\Users\Carlos\AppData\Local\atom\bin;C:\Users\Carlos\AppData\Local\GitHubDesktop\bin
14 verbose lifecycle carlos_valencia_portfolio@0.1.0~deploy: CWD: C:\Users\Carlos\ReactJSProjects\carlos_valencia_portfolio
15 silly lifecycle carlos_valencia_portfolio@0.1.0~deploy: Args: [ '/d /s /c', 'gh-pages -d build' ]
16 silly lifecycle carlos_valencia_portfolio@0.1.0~deploy: Returned: code: 1 signal: null
17 info lifecycle carlos_valencia_portfolio@0.1.0~deploy: Failed to exec deploy script
18 verbose stack Error: carlos_valencia_portfolio@0.1.0 deploy: gh-pages -d build
18 verbose stack Exit status 1
18 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:304:16)
18 verbose stack at EventEmitter.emit (events.js:182:13)
18 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
18 verbose stack at ChildProcess.emit (events.js:182:13)
18 verbose stack at maybeClose (internal/child_process.js:962:16)
18 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:249:5)
19 verbose pkgid carlos_valencia_portfolio@0.1.0
20 verbose cwd C:\Users\Carlos\ReactJSProjects\carlos_valencia_portfolio
21 verbose Windows_NT 10.0.17134
22 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "deploy"
23 verbose node v10.8.0
24 verbose npm v6.2.0
25 error code ELIFECYCLE
26 error errno 1
27 error carlos_valencia_portfolio@0.1.0 deploy: gh-pages -d build
27 error Exit status 1
28 error Failed at the carlos_valencia_portfolio@0.1.0 deploy script.
28 error This is probably not a problem with npm. There is likely additional logging output above.
29 verbose exit [ 1, true ]
I have no idea what is going on, I read things online saying that I am not pointing at the folder that contains my sh.exe and that I have to specify it in my environment variables and whatnot. I literally tried everything I found in both google, bing and reddit. Im literally stumped and want to cry lol. Please help!
回答1:
It would be helpful to see your package.json
values for homepage
, and in the scripts
object, the predeploy
and deploy
values. That being said, here is how to deploy a React app to Github Pages:
- After building your app and pushing to your github repo, install
gh-pages
by running the following in terminal:npm install --save gh-pages
Update your
package.json
with the following:"homepage": "https://[github-username].github.io/[repo-name]"
- Inside your
scripts
object:"predeploy": "npm run build",
"deploy": "gh-pages -d build"
- Run
npm run deploy
回答2:
Would be helpful if you could add some code but might be worth checking out the bottom reply on this post:
https://github.community/t5/GitHub-Pages/My-react-project-doesn-t-work-on-github-pages/m-p/6806#M452
In particular, this section on client-side routing (if applicable to your application):
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#notes-on-client-side-routing
来源:https://stackoverflow.com/questions/52654582/cannot-deploy-reactjs-app-to-github-pages