【发布时间】:2018-04-11 12:51:43
【问题描述】:
我在我的一个项目中使用 gulp。从操作系统(Arch Linux)运行gulp watch 时
fs.js:921
return binding.readdir(pathModule.toNamespacedPath(path), options.encoding);
^
Error: EACCES: permission denied, scandir '/tmp/systemd-private-c33e4391b18f4b24af3055190fb15730-systemd-hostnamed.service-zrxyaX/'
at Object.fs.readdirSync (fs.js:921:18)
at Gaze._addToWatched (/home/majmun/code/wp/wp-content/plugins/project/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:274:22)
at Gaze._internalAdd (/home/majmun/code/wp/wp-content/plugins/project/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:191:10)
at /home/majmun/code/wp/wp-content/plugins/project/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:400:16
at Array.forEach (<anonymous>)
at /home/majmun/code/wp/wp-content/plugins/project/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:396:12
at FSReqWrap.oncomplete (fs.js:153:20)
我正在从主机操作系统而不是从虚拟机运行 gulp,因为它要快得多。
我知道问题是 gulp 在主机操作系统的/tmp 文件夹中执行某些操作,并且某些文件具有 root 权限。
如果我运行 sudo chown -R majmun:users /tmp,之后会出现一个具有 root 权限的新文件,它会破坏 gulp。
为什么 gulp watch 需要/tmp 文件夹。
有人解决了这个问题吗?
这里是 gulp watch 任务的代码 // gulp 观看
Gulp.task('watch', ['dev'], function() {
console.log('Initializing assets watcher:')
let stream = new Stream();
let filter = '*.{css,scss,sass,less,js,png,jpg,jpeg,svg}';
let tmp = Tmp.fileSync();
let glob = [
path.src.assets + '**/' + filter,
path.src.elements + '**/' + filter,
path.src.properties + '**/' + filter,
];
for (let i = 0; i < glob.length; i++) {
console.log('- ' + glob[i]);
}
let watcher = Gulp.watch(glob, ['dev']);
watcher.add(tmp.name);
process.on('SIGINT', function() {
stream.emit('end');
process.exit(0);
});
KeyPress(process.stdin);
process.stdin.on('keypress', function(char, key) {
if (key && key.ctrl && key.name == 'c') {
process.emit('SIGINT');
}
else if (key && key.ctrl && key.name == 'r') {
Fs.utimes(tmp.name, new Date(), new Date(), function() {});
}
});
process.stdin.setRawMode(true);
process.stdin.resume();
console.log('Watcher up and running, Ctrl+R to refresh, Ctrl+C to exit.');
return stream;
});
【问题讨论】:
-
请问您是如何安装 gulp 的?
-
@funilrys 我通过 yaourt 从 AUR (archlinux.org/packages/community/any/gulp) 安装了 gulp,还使用
npm install安装了所有项目节点模块 -
你能发布你的 Gulpfile 的内容吗?
标签: javascript gulp archlinux gulp-watch