gulp.watch task is throwing an error: (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR - node.js

This recently started happening in my gulp.watch task. It was working fine as of two weeks ago.
When I run $ gulp
when it gets to the watch task, it throws the following:
(FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-21)
events.js:85
throw er; // Unhandled 'error' event
^
Error: watch EMFILE
at exports._errnoException (util.js:746:11)
at FSEvent.FSWatcher._handle.onchange (fs.js:1157:26)
Per a few suggestions, I have updated node.js, with no luck.
There was also the suggestion that I was trying to watch too many files, so I changed the watch dir to a single file. Still throws the error.
Ive updated gulp to 3.9 globally and locally, along with my dependencies. I even rolled gulp back to an older version on both to see if that worked. No luck.
What could be throwing this on a gulp.watch task?
Here is my gulpfile task:
// Watch
gulp.task('watch', function() {
// Listen on port 35729
server.listen(35729, function (err) {
if (err) {
return console.log(err)
};
// Watch .scss files
gulp.watch('assets/styles/*.scss', ['styles']);
});
});

From the code you've posted, you've invoked gulp.watch but with no instruction as to what should happen when a file changes?
Normally a watch task would trigger the running of another task upon a file change. One would assume that watching changes in scss files should trigger scss compilation.
gulp.watch('assets/styles/style.scss', ['scss:compile']);
// where 'scss:compile' is another defined task for scss compilation.
Hope that helps you out and might give you some different output :)

Related

Use NodeJS's process in Vue CLI project

I have a challenge using the Node's process.on function in the Vue CLI project's main.js file.
I have the following code in the file.
process.on("unhandledRejection", function(reason, promise){
console.log("Unhandled", reason, promise); // log all your errors, "unsuppressing" them.
throw reason; // optional, in case you want to treat these as errors
});
The project builds but when the app is opened on the browser, I get an error:
Uncaught TypeError: process.on is not a function
How do I configure the project so that I can use the Node's process?
Am I not understanding NodeJS in this context?
Is there something I am missing?
Any assistance is appreciated thanks.

gulp.src().on('error', ()=>{}) is not getting triggered when file specified in src is not found

I am trying to concatinate multiple files using gulp and gulp-concat modules of npm.
The following is the code snippet I have used.
gulp.src(['../a.js', '../b.js', '../c.js'])
.pipe(concat('destination.js'))
.pipe(gulp.dest('destination/path/'))
.on('error', () => {
console.error('Error');
})
.on('finish', () => {
console.log('Success');
});
The error event listener is not getting triggered when the file for suppose b.js or anyother is not found in the specified path.
The event finish is getting triggered anyway.
How do find error such as file not found in this process?
Thanks for the help in advance
I finally found a solution for this from the below post
How to make Gulp.src fail if a file is missing?
I Used the files-exist npm package to check if all files exist or not.
You can use gulp-plumber to get error while build.
Example:
Step 1: Install gulp-plumber:
npm i gulp-plumber --save-dev
Step 2: Require the gulp plmber module in gulpfile:
var plumber = require('gulp-plumber');
Step 3: Usage
gulp.src(['../a.js', '../b.js', '../c.js'])
.pipe(plumber())
.pipe(concat('destination.js'))
.pipe(plumber.stop())
.pipe(gulp.dest('dist/js'));

Unable to put Sails.js app in production

I'm trying to put my app into production with Sails.js, but cannot get past the grunt tasks. This is the error I'm receiving:
error: Error: The hook `grunt` is taking too long to load.
Make sure it is triggering its `initialize()` callback, or else set
`sails.config.grunt._hookTimeout to a higher value (currently 20000)
at tooLong [as _onTimeout]
(/usr/local/lib/node_modules/sails/lib/app/private/loadHooks.js:92:21)
at Timer.listOnTimeout (timers.js:110:15)
I have increased sails.config.grunt._hookTimeout dramatically and still the process hasn't been completed. Running a sails debug in either production or development outputs:
Grunt :: Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Agent.Server._listen2 (net.js:1156:14)
at listen (net.js:1182:10)
at Agent.Server.listen (net.js:1267:5)
at Object.start (_debugger_agent.js:20:9)
at startup (node.js:86:9)
at node.js:814:3
I find it very strange that in development mode everything works fine, but its not the case in production. The files included are pretty big, such as angular, moment and other modules. This is how the jsFilesToInject looks:
var jsFilesToInject = [
// Load sails.io before everything else
'js/dependencies/sails.io.js',
'js/dependencies/angular.min.js',
'js/dependencies/moment.min.js',
'js/dependencies/angular-ui-router.min.js',
'js/dependencies/angular-sails.min.js',
'js/dependencies/angular-moment.min.js',
'js/dependencies/angular-animate.min.js',
'js/dependencies/angular-aria.min.js',
'js/dependencies/angular-material.min.js',
// All of the rest of your client-side js files
// will be injected here in no particular order.
'js/**/*.js'
];
I'm not sure what else would be causing this, any suggestions? I'm using Sails version 0.11.0
I just had this same problem and it was just that the timeout was not big enough I had to put this in my config/local.js file:
module.exports = {
hookTimeout: 120000
};
I just posted the same issue on github, and then checked out the source code. So I read through the grunt hook to understand what happens. And it turns out that in default mode the grunt hook triggers the callback right after grunt has started, but for the prod mode it is triggered only when grunt has finished all the tasks.
There is a following comment in the source code:
cb - optional, fires when the Grunt task has been started (non-production) or finished (production)
So if there is anything watching (like using watch in browserify) in prod, grunt task will never exit, and therefore grunt hook will always timeout. But even if nothing is watching, starting the grunt task takes much longer that finishing all the tasks, and this explains why we don't see the problem when not in production mode.
Since modifying the original grunt hook is not the best idea (it lives in node_modules), the best is indeed to increase (possibly dramatically) the _hookTimeout option and to make sure grunt task exits (for this it can be run separately with grunt prod).

Gulp.js can't compile angular.js project due to excessive js errors?

I am trying to move from Grunt to Gulp. This project has run fine under Grunt, so I must be doing something wrong in Gulp.
All the other tasks work except scripts. I have tired now adding and commenting out sections.
I keep getting an error relating to an unexpected token. Using mg-min:
stream.js:94
throw er; // Unhandled stream error in pipe.
^
Error: Line 2: Unexpected token :
at throwError (/Users/stevelombardi/Documents/dsg/node_modules/gulp-ngmin/node_modules/ngmin/node_modules/esprima/esprima.js:1156:21)
With ng-min commented out and using Uglify (default):
Error caught from uglify: Unexpected token: punc (:) in /Users/stevelombardi/Documents/dsg/dist/scripts/main.min.js. Returning unminifed code
[gulp] gulp-notify: [Gulp notification] Scripts task complete
[gulp] Finished 'scripts' after 2.97 s
I'm stumped. Here's the task:
// Scripts
gulp.task('scripts', function() {
return gulp.src([
"bower_components/jquery/jquery.js",
"bower_components/angular/angular.js",
"bower_components/bootstrap/dist/js/bootstrap.js",
"bower_components/modernizr/modernizr.js",
"bower_components/angular-resource/angular-resource.js",
"bower_components/angular-cookies/angular-cookies.js",
"bower_components/angular-sanitize/angular-sanitize.js",
"bower_components/angular-route/angular-route.js",
"bower_components/jquery.easy-pie-chart/dist/angular.easypiechart.js",
"bower_components/angular-bootstrap/ui-bootstrap.min.js",
"bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js",
"bower_components/kapusta-jquery.sparkline/dist/jquery.sparkline.js",
"bower_components/leaflet-dist/leaflet.js",
"bower_components/angular-leaflet/dist/angular-leaflet-directive.js",
"bower_components/ngprogress/build/ngProgress.js",
"bower_components/angular-bootstrap-toggle-switch/angular-toggle-switch.js",
"bower_components/flot/jquery.flot.js",
"bower_components/flot/jquery.flot.resize.js",
"bower_components/flot.tooltip/js/jquery.flot.tooltip.js",
"bower_components/angular-flot/angular-flot.js",
'src/scripts/**/*.js',
])
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
// .pipe(ngmin({
// dynamic: false
// }))
// .pipe(gulp.dest('dist/scripts'))
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/scripts'))
.pipe(rename({
suffix: '.min'
}))
.pipe(uglify())
.pipe(gulp.dest('dist/scripts'))
.pipe(notify({
message: 'Scripts task complete'
}));
});
I think it's safe to say that the output from the two plugins together can be taken to indicate that you have a syntax error on line two of what is being passed to the ngmin or uglify.
The two plugins are just reacting a bit differently from each other. One is helpfully telling you the line number, and the other is helpfully tell you the file name.
Since you've already renamed the file, it seems like they're talking about a file that is already minified, when in fact it's just that you renamed its in-memory representation prematurely.
For starters, I'd recommend not renaming the file until you have minified it because your error is confusing. At that point, you'll probably see that the error appears in the file that is saved to dist/scripts/main.js (on line two of that file you apparently have an errant colon).

Node.js – events js 72 throw er unhandled 'error' event

I'm new to Node.js and wish to run a program using streams. With other programs, I had to start a server simultaneously (mongodb, redis, etc) but I have no idea if I'm supposed to run one with this. Please let me know where I am going wrong and how I can rectify this.
This is the program:
var http = require('http'),
feed = 'http://isaacs.iriscouch.com/registry/_changes?feed=continuous';
function decide(cb) {
setTimeout(function () {
if (Date.now()%2) { return console.log('rejected'); }
cb();
}, 2000);
}
http.get(feed, function (res) {
decide(res.pipe.bind(res, process.stdout));
//using anonymous function instead of bind:
// decide(function () {
// res.pipe(process.stdout)
// });
});
This is the cmd output:
<b>C:\05-Employing Streams\05-Employing Streams\23-Playing with pipes>node npm_stre
am_piper.js
events.js:72
throw er; // Unhandled 'error' event
^
Error: Parse Error
at Socket.socketOnData (http.js:1583:20)
at TCP.onread (net.js:527:27)
</b>
Close nodejs app running in another shell.
Restart the terminal and run the program again.
Another server might be also using the same port that you have used for nodejs. Kill the process that is using nodejs port and run the app.
To find the PID of the application that is using port:8000
$ fuser 8000/tcp
8000/tcp: 16708
Here PID is 16708 Now kill the process using the kill [PID] command
$ kill 16708
I had the same problem. I closed terminal and restarted node. This worked for me.
Well, your script throws an error and you just need to catch it (and/or prevent it from happening). I had the same error, for me it was an already used port (EADDRINUSE).
I always do the following whenever I get such error:
// remove node_modules/
rm -rf node_modules/
// install node_modules/ again
npm install // or, yarn
and then start the project
npm start //or, yarn start
It works fine after re-installing node_modules. But I don't know if it's good practice.
Check your terminal it happen only when you have your application running on another terminal..
The port is already listening..
For what is worth, I got this error doing a clean install of nodejs and npm packages of my current linux-distribution
I've installed meteor using
npm install metor
And got the above referenced error. After wasting some time, I found out I should have used meteor's way to update itself:
meteor update
This command output, among others, the message that meteor was severely outdated (over 2 years) and that it was going to install itself using:
curl https://install.meteor.com/ | sh
Which was probably the command I should have run in the first place.
So the solution might be to upgrade/update whatever nodejs package(js) you're using.

Resources