Recently, when attempting to use the gulp command in the Terminal app, I saw an error message saying Error: EPERM: operation not permitted, uv_cwd. In this tutorial, you’ll learn how to solve this problem.

How to fix: Error: EPERM: operation not permitted, uv_cwd

What causes this error

In my case, the below error appeared when attempting to run the gulp command inside my app project directory in the Terminal app.

$ gulp build
    cachedCwd = rawMethods.cwd();

Error: EPERM: operation not permitted, uv_cwd
    at process.wrappedCwd [as cwd] (internal/bootstrap/switches/does_own_process_state.js:129:28)
    at Yargs (/usr/local/lib/node_modules/gulp-cli/node_modules/yargs/yargs.js:33:27)
    at Argv (/usr/local/lib/node_modules/gulp-cli/node_modules/yargs/index.js:11:16)
    at Object.\<anonymous\> (/usr/local/lib/node_modules/gulp-cli/node_modules/yargs/index.js:6:1)
    at Module.\_compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module.\_extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module.\_load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18) {
  errno: -1,
  code: 'EPERM',
  syscall: 'uv_cwd'

This seemed strange to me because I had just used the gulp tool and everything was fine. Then I tried to use the bundle update command, thinking that this can be a hint to localize the problem.

$ bundle update
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
Traceback (most recent call last):
	9: from /usr/local/bin/bundle:23:in \<main\>
	8: from /Library/Ruby/Site/2.6.0/rubygems.rb:294:in `activate_bin_path'
	7: from /Library/Ruby/Site/2.6.0/rubygems.rb:264:in `find_spec_for_exe'
	6: from /Library/Ruby/Site/2.6.0/rubygems/dependency.rb:284:in `matching_specs'
	5: from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:45:in `filter!'
	4: from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:7:in `bundler_version'
	3: from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:22:in `bundler_version_with_reason'
	2: from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:73:in `lockfile_version'
	1: from /Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:85:in `lockfile_contents'
/Library/Ruby/Site/2.6.0/rubygems/bundler_version_finder.rb:85:in pwd': Operation not permitted - getcwd (Errno::EPERM)

The error appeared again, but now the error message is self explanatory. It saying that the shell-init cannot access parent directories, and this is because error retrieving current directory.

In my case, this makes sense because I used the Finder to delete my app project catalog and restore it from the backup after trying new things and changed my mind to keep them. Facepalm >_<

Now we know what caused this error.

How to solve it

Once we know what is causing the gulp run to fail, we can use it to solve the problem. It is a really easy process. To solve this problem, we just need to re-enter into our app project directory. Now, step by step guide.

In the Terminal app, type the following command and press the Enter key to go up one level in the directory.

cd ../

Now, type the following command and press the Enter key to navigate to your working directory (in this example the my_app_dir catalog is used).

cd my_app_dir

Important! In my case the working directory is the catalog of my app project called my_app_dir where the problem has occurred. Change the command above to suit your case.


That’s it, you’re done. Now the gulp should run without the Error: EPERM: operation not permitted, uv_cwd error. So simple isn’t it?

If you are having trouble fixing this problem with the instructions above, but are being able to solve this problem with any another method please describe it in the comment section below. Thanks!

I hope this article has helped you learn how to fix the Error: EPERM: operation not permitted, uv_cwd error. If this article has helped you then please leave a comment :smiley:

Thanks for reading!