EPERM error when starting Gulp as non-root

I use Gulp to compile some assets into a simple standalone WordPress theme project.

When I run the Gulp task, which compiles some LESS files, I get the following error:

stream.js:94 throw er; // Unhandled stream error in pipe. ^ Error: EPERM, chmod '/Users/harryg/Sites/sites/wordpress/wp-content/themes/samarkand-2/assets/css/main.min.css' 

When I run it as sudo , the task runs without problems.

Thinking it was a permission error, I chmod'd the entire theme folder and its contents until 777, but this does not solve the problem. I have Gulp installed globally, which may be a problem, but I'm not sure how to solve it.

EDIT

Even if I run local gulp, I get the same error. That is, running node_modules/.bin/gulp from my project folder leads to the same EPERM error.

+6
source share
3 answers

While @cwelske gives a “hacky” workaround in its answer, the link it provides in the bug report provides the best fix for Gulp 3: use vinyl-fs .

npm install vinyl-fs --save-dev

Change your gulpfile to use VFS:

Add to your block: var vfs = require('vinyl-fs');

Change the output channel: .pipe(vfs.dest('./output'));

The reason I ran into this error was because the files belonged to a more general group and user, so several team members could work together on the project. Obviously, Ubuntu does not allow you to chmod create other files. I suspect the OP is in a similar situation (the web server may own the files).

If you do not require such a setting, another option is to change the files belonging to your user, for example:

sudo chown -R me:me .

Setting permissions on 777 files will not help you, because if you do not own the file, you cannot chmod without sudo. (Therefore, it works when you start Gulp as sudo.)

+2
source
 `sudo chown -R `whoami` sites/wordpress/wp-content/themes/samarkand-2` 

must fix it. Or any other directory you want to start from. This is not dangerous and can happen due to you node -installation. It is quite common and should be fixed in general after starting the installation using npm@3.X.X

+1
source

gulp 3.x has an error that makes it want to chown all files, regardless of whether it already has all the necessary permissions or not. It is supposed to be fixed in gulp 4.

The related error contains a good workaround if you know the files have the correct permissions: just replace fs.chmod an empty function in your gulpfile.js :

 var fs = require('fs'); if (1) fs.chmod = function (a, b, cb) { cb(0); } 
+1
source

Source: https://habr.com/ru/post/983341/


All Articles