I cannot figure out why I am getting a node ENOENT error, when running a simple task to clean out my vendor files.
My gulp task looks like this
var gulp = require('gulp');
var del = require('del');
module.exports = function(opt){
gulp.task('clean:vendor', function(cb){
return del(['src/vendor/'],cb)
});
}
When I run the command gulp clean:vendor against a file structure that looks like this:
gulpfile.js
src/vendor/js
src/vendor/css
I get this error from node, and I cannot figure out how to catch or fix.
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, open '/Users/aycollin/seed/src/vendor/js/bootstrap.js'
Related
Our Gulp build process fails for some new developers like this:
events.js:85
throw er; // Unhandled 'error' event
^
Error: EMFILE, open '[some filename]'
at Error (native)
The solution is to run:
ulimit -n 2048
So I'd like to catch the EMFILE error and replace it with a friendlier message. However, even wrapping the entire gulpfile.js in a try/catch doesn't seem to contain it.
It turns out that wrapping try/catch around everything doesn't work because the errors happen after (all) the code is executed. Injecting an error handler into every single pipe works:
function onError(e) {
if (e.code === 'EMFILE') {
console.error('Too many open files. You should run this command:\n ulimit -n 2048');
process.exit(1);
}
gutil.log(e.message);
process.exit(1);
}
...
var result = bundler.bundle();
result = result
.on('error', onError)
.pipe(source(name))
.pipe(buffer());
I'm attempting to run the following Gulp task to compile Sass files, using the plugin, gulp-compass on OS X Yosemite 10.5.5.
var path = require("path");
var gulp = require("gulp");
var compass = require("gulp-compass");
gulp.task("compile2013Base", function() {
var projectPath = path.join(__dirname, '../../ ');
gulp.src(['../sass/desktop/css/2013/*.scss']).pipe(compass({
project: projectPath,
css: 'htdocs/assets/css/2013/',
sass: 'sass/desktop/css/2013'
})).on('error', errorHandler).pipe(gulp.dest('../../htdocs/assets/css/2013/'));
});
function errorHandler (error) {
console.log(error.toString());
this.emit('end');
}
However, when I try to run the task like gulp compile2013Base, I get the following error:
> gulp compile2013Base
[13:39:06] Using gulpfile [**redacted**]/scripts/js/gulpfile.js
[13:39:06] Starting 'compile2013Base'...
[13:39:06] Finished 'compile2013Base' after 9.07 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn /usr/bin/compass ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
I already have compass installed at /usr/bin/compass, and running compass in the terminal does not show any errors.
I'm not sure what to go on here, how do I get the error details?
This is helped me
sudo gem install -n /usr/local/bin compass
see Error: "compass:dist" Fatal error: spawn /usr/bin/compass ENOENT
Whenever the appropriate files change I would like to bundle my tests and start karma, showing any failed tests.
I currently have the watch task:
gulp.task('default', ['browserify', 'css','runTests'], function () {
gulp.watch('./src/js/**/*.js', ['browserify']);
gulp.watch('./src/js/**/*.js', ['runTests']);
});
Which starts up the runTests.js
var testFile = [
'./src/components/tests/suite.js'
];
// bundle tests
var cmd = child.spawn('browserify', ['-e', './src/components/tests/suite.js', '-t', 'reactify', '-t']);
cmd.on('close', function (code) {
//cmd finished start karma
gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
throw err;
});
});
my console currently errors here:
[17:04:27] Starting 'runTests'...
[17:04:27] Finished 'runTests' after 2.73 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn browserify ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
Process finished with exit code 1
I can get a basic command to work child = spawn("ls");
But not the browserify command, can anyone help?
You can use the browserify API within a gulp task. Look at substack/node-browserify#1170 for some tips on globbing with browserify. Then you can just include the output file in your karam config files array.
// Disclaimer: This code is untested
var files = require("glob").sync('./src/js/**/*.js');
files.push('./src/components/tests/suite.js');
var browserify = require("browserify")(files, {transform: 'reactify'});
// your can do more config on the browserify instance
// Run browserify bundle and output to a file
var myFile = require('fs').createWriteStream('myOutput.txt');
browserify.bundle().pipe(myFile);
I am using gulp to copy and clean my front-end projects. I want to run some sequential tasks. It means, for example, I want the copy task to be started and finished and then run its the following task (a copy task).
I frequently see this error when I run my tasks:
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, lstat '/home/reza/projects/account-web/dist/views'
After lstat, each I see a file name randomly. I just find that when there is no dist folder or it is empty copy tasks run properly but when the dist folder is not empty even clean task throws and error.
There are my gulp file and command results below:
var gulp = require('gulp');
var clean = require('gulp-clean');
var merge = require('gulp-merge');
var runSequence = require('run-sequence');
gulp.task('clean', function () {
gulp.src('./dist/**').pipe(clean());
});
gulp.task('copy-js', function () {
return gulp.src('app/js/**').pipe(gulp.dest('dist/js/'));
});
gulp.task('copy-bower', function () {
return gulp.src('bower_components/**').pipe(gulp.dest('dist/bower_components/'));
});
gulp.task('copy-script', function () {
return gulp.src('app/scripts/**').pipe(gulp.dest('dist/scripts/'));
});
gulp.task('copy-styles', function () {
var stream1 = gulp.src('app/styles/**').pipe(gulp.dest('dist/styles/'));
var stream2 = gulp.src('app/fonts/**').pipe(gulp.dest('dist/fonts/'));
var stream3 = gulp.src('app/img/**').pipe(gulp.dest('dist/img/'));
return merge(stream1, stream2, stream3);
});
gulp.task('copy-views', function () {
var stream1 = gulp.src('app/views/**').pipe(gulp.dest('dist/views/'));
var stream2 = gulp.src('app/*').pipe(gulp.dest('dist/'));
return merge(stream1, stream2);
});
gulp.task('dist', function () {
runSequence(['copy-bower','copy-js', 'copy-script', 'copy-styles', 'copy-views']);//
});
gulp.task('dev', function () {
runSequence('clean', 'dist')
});
gulp.task('default', ['dev']);
I thought that there is concurrency problem and the tasks are not running really sequentially, so I tries some modules to solve this problem like runSequence.
➜ account-web git:(master) ✗ gulp clean
[14:20:55] Using gulpfile ~/projects/account-web/Gulpfile.js
[14:20:55] Starting 'clean'...
[14:20:55] Finished 'clean' after 5.58 ms
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, lstat '/home/reza/projects/account-web/dist/views'
➜ account-web git:(master) ✗ gulp dev
[14:35:03] Using gulpfile ~/projects/account-web/Gulpfile.js
[14:35:03] Starting 'dev'...
[14:35:03] Starting 'clean'...
[14:35:03] Finished 'clean' after 5.47 ms
[14:35:03] Starting 'dist'...
[14:35:03] Starting 'copy-bower'...
[14:35:03] Starting 'copy-js'...
[14:35:03] Starting 'copy-script'...
[14:35:03] Starting 'copy-styles'...
[14:35:03] Starting 'copy-views'...
[14:35:03] Finished 'dist' after 14 ms
[14:35:03] Finished 'dev' after 22 ms
stream.js:94
throw er; // Unhandled stream error in pipe.
^
Error: ENOENT, open '/home/reza/projects/account- web/dist/styles/fonts.css'
I wonder if it's attempting to asynchronously delete a file within a nested folder after the nested folder has already been deleted. Try changing your src to include the dist folder without the wildcards. This will tell it to delete the dist folder instead of each item independently.
gulp.task('clean', function () {
gulp.src('./dist').pipe(clean());
});
It also appears that gulp-clean has been deprecated, you may want to checkout del as a replacement. It is able to handle your original glob pattern correctly.
I run cssnext (1.3.0) with gulp (3.8.11) on docker (1.6) container (official node image) and my OS is ArchLinux (host). The node version is 0.10.38. I have a problem, i can't solve. This is my gulpfile.js:
var gulp = require('gulp');
var cssnext = require("gulp-cssnext");
gulp.task("css4Tocss", function() {
gulp.src("css/index.css")
.pipe(cssnext({
compress: true
}))
.pipe(gulp.dest("dist"))
});
When i run:
gulp css4Tocss
i get the following error:
events.js:72
throw er; // Unhandled 'error' event
^
TypeError: undefined is not a function
at LazyResult.run (/app/node_modules/cssnext/node_modules/postcss/lib/lazy-result.js:193:24)
at LazyResult.sync (/app/node_modules/cssnext/node_modules/postcss/lib/lazy-result.js:179:32)
at LazyResult.stringify (/app/node_modules/cssnext/node_modules/postcss/lib/lazy-result.js:210:14)
at LazyResult._createClass.get (/app/node_modules/cssnext/node_modules/postcss/lib/lazy-result.js:232:25)
at cssnext (/app/node_modules/cssnext/index.js:220:20)
If you have an idea, i'm interested ^^.
Looks like there's an issue in the latest version of this module. Downgrading to "gulp-cssnext": "0.6.0" fixed this issue for me.
Either that or you can follow the issue above!