事件.js:160 抛出er; //未处理的“错误”事件

32

我所参与的项目是使用gulp构建的。

最近我将node版本更新到了v6.3.1,然后出现了一些问题。

一个名为“html”的任务抛出了一个错误。以下是它的部分错误代码。

bogon:toClient work$ gulp html
(node:2519) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.

[10:26:10] Using gulpfile ~/Project/TIME_Cancer_Treatment_Centers_of_America(CTCA)/toClient/gulpfile.js
[10:26:10] Starting 'html'...
(node:2519) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.

events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: CSS parse error scripts/vendor.js: Unexpected input
    1 |!function(t,e){"object"==typeof module&&"object"==typeof module.exports?module.exports=t.document?e(t,!0):function(t){if(!t.document)throw new Error("jQuery requires a window with a document");return e(t)}:e(t)}("undefined"!=typeof window?window:this,function(t,e){function i(t){var e="length"in t&&t.length,i=J.type(t);return"function"!==i&&!J.isWindow(t)&&(!(1!==t.nodeType||!e)||("array"===i||0===e||

任务 'html' 的代码:

var $ = require('gulp-load-plugins')();

gulp.task('html', function() {
  var assets = $.useref.assets({searchPath: ['.tmp']});

  return gulp.src('app/*.html')
    .pipe(assets)
    .pipe($.if('*.js', $.uglify()))
    .pipe($.if('*.css', $.csso()))
    .pipe(assets.restore())
    .pipe($.useref())
    .pipe($.if('*.html', $.minifyHtml({conditionals: true, loose: true})))
    .pipe(gulp.dest('dist'));
});

我曾经搜索了很多,但是没有找到适合我的正确答案。


2
可能是重复的问题:Node.js - events js 72 throw er unhandled 'error' event - Jonny Henly
https://dev59.com/ma3la4cB1Zd3GeqPK1KH - Dinesh Naik
13个回答

65

对我来说,每次重启电脑后都需要清除。有没有什么方法可以避免这个问题? - Bruno Francisco

16

关于以下行的错误:

events.js:160
      throw er; // Unhandled 'error' event

问题在于我已经打开了另一个本地节点应用的端口。

停止其他应用程序解决了该问题。


6
这个问题一直困扰着我,但这个答案让我欣慰不少,干杯! - Ryan Cocuzzo

6

当我在Ubuntu上运行npm start命令时,我遇到了类似的错误。

当我运行sudo npm start命令时,问题得到了解决。

我认为问题可能是应用程序没有足够的权限。


在我的情况下,这是在重命名由create-app命令创建的原始文件夹后发生的。记住这一点。 - Btc Sources

2

尝试杀掉其他的 gulp 进程。

ps -ax | grep gulp
kill -9 <number>

2

最近,我将Node版本更改为v5.10.0,并且一切都正常运行。


1

我在Ubuntu上运行npm start命令时遇到了类似的错误。

通过运行sudo npm start解决了我的问题。

我认为这是因为文件夹对Morgan日志记录器没有写入权限。


1

我在启动laravel-echo-server npm包时遇到了同样的错误。请参考附图。如果您因为任何npm包而出现错误,我认为这个答案会对您有所帮助。

enter image description here

我是如何找到解决方法的:

  • 我的域名没有正确配置。查看图片,我试图访问pid.contentcentral.co域名,但该域名已被禁用或未正确配置。因此出现错误。更正配置后问题得到解决。

其他重要点:

  • 错误:在Node.js中监听EADDRNOTAVAIL错误

    当您在错误中看到这行时,不是端口而是您的IP地址/域名出了些问题。

  • 错误:在Node.js中监听EADDRINUSE错误

    当您在错误中看到这行时,不是您的IP地址/域名,而是端口出了些问题,可能已经被占用。


请添加一些代码,以便其他用户可以测试您所描述的内容。谢谢! - Ignacio Ara

1
在我的情况下,端口已经被使用了。
# netstat -nltp

检查是否有正在使用的端口,如果有,请更改端口并尝试重新启动。

在某些情况下,如果使用静态IP地址,则可能会出现IP地址错误的情况。


1

events.js:160

这是因为:
1. 端口被另一个节点使用,所以你需要从 server.js 更改节点的端口。 2. 或者停止使用相同端口的其他应用程序。

1
我遇到了与 events.js 相似的问题。
[19:59:06] Starting 'jekyll-async'...

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: spawn ENOENT
    at errnoException (child_process.js:1011:11)
    at Process.ChildProcess._handle.onexit (child_process.js:802:34)

在我的情况下,问题出现是因为我忘记从Gemfile中安装gems(在完成系统重新安装后)。
所以,对我来说解决方法是:
gem install jekyll

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接