fatal: could not create work tree dir : Permission denied (while deploying react app)

Viewed 294

I'm learning react.js and trying to build a react app. I want to deploy my app up to GitHub, but when I run "npm run deploy", it shows:

> my-app@0.1.0 deploy /Users/rnryno/my-app
> gh-pages -d build

fatal: could not create work tree dir '../../../usr/local/lib/node_modules/gh-pages/.cache/git@github.com!hcy1219!my-app.git': Permission denied

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app@0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the my-app@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!     /Users/rnryno/.npm/_logs/2020-06-08T03_38_20_209Z-debug.log

and here's the log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'deploy' ]
2 info using npm@6.14.4
3 info using node@v12.18.0
4 verbose run-script [ 'predeploy', 'deploy', 'postdeploy' ]
5 info lifecycle my-app@0.1.0~predeploy: my-app@0.1.0
6 verbose lifecycle my-app@0.1.0~predeploy: unsafe-perm in lifecycle true
7 verbose lifecycle my-app@0.1.0~predeploy: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/rnryno/my-app/node_modules/.bin:/usr/local/node-v1.22.4/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/opt/X11/bin:/Users/rnryno/Library/Android/sdk/tools:/Users/rnryno/Library/Android/sdk/platform-tools:
8 verbose lifecycle my-app@0.1.0~predeploy: CWD: /Users/rnryno/my-app
9 silly lifecycle my-app@0.1.0~predeploy: Args: [ '-c', 'npm run build' ]
10 silly lifecycle my-app@0.1.0~predeploy: Returned: code: 0  signal: null
11 info lifecycle my-app@0.1.0~deploy: my-app@0.1.0
12 verbose lifecycle my-app@0.1.0~deploy: unsafe-perm in lifecycle true
13 verbose lifecycle my-app@0.1.0~deploy: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/rnryno/my-app/node_modules/.bin:/usr/local/node-v1.22.4/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/opt/X11/bin:/Users/rnryno/Library/Android/sdk/tools:/Users/rnryno/Library/Android/sdk/platform-tools:
14 verbose lifecycle my-app@0.1.0~deploy: CWD: /Users/rnryno/my-app
15 silly lifecycle my-app@0.1.0~deploy: Args: [ '-c', 'gh-pages -d build' ]
16 silly lifecycle my-app@0.1.0~deploy: Returned: code: 1  signal: null
17 info lifecycle my-app@0.1.0~deploy: Failed to exec deploy script
18 verbose stack Error: my-app@0.1.0 deploy: `gh-pages -d build`
18 verbose stack Exit status 1
18 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
18 verbose stack     at EventEmitter.emit (events.js:315:20)
18 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
18 verbose stack     at ChildProcess.emit (events.js:315:20)
18 verbose stack     at maybeClose (internal/child_process.js:1021:16)
18 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
19 verbose pkgid my-app@0.1.0
20 verbose cwd /Users/rnryno/my-app
21 verbose Darwin 18.7.0
22 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "deploy"
23 verbose node v12.18.0
24 verbose npm  v6.14.4
25 error code ELIFECYCLE
26 error errno 1
27 error my-app@0.1.0 deploy: `gh-pages -d build`
27 error Exit status 1
28 error Failed at the my-app@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 spend almost 2 days on this problem, trying every method I found, including authorizing the file, clearing the cache, etc. But none of them work. Please help me QQ

1 Answers

So after another 2 hours working I figure out the solution. It seems that I thought I've changed the authorization in the correct directory but actually not. For example, it said

fatal: could not create work tree dir '../../../usr/local/lib/node_modules/gh-pages/.cache/git@github.com!hcy1219!my-app.git': Permission denied

and after I typed in

sudo chown -R <username> /usr/local/lib/node_modules/gh-pages/.cache

It works. I'm so happy. I'll keep this post in case someone met same problem. Since I'm new to this and not sure I'm explaining this correctly, if you have any advice or other solution, please comment below. Thanks!

Related