今天想帮着同事把AngularJS的前端项目进行优化一下,增加index注入部分,结果node直接报错node:17232.具体错误如下:
(node:17232) UnhandledPromiseRejectionWarning
(node:17232) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:17232) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
采用的是webstorm开发环境,采用的是node8.15.0,gulp-inject为4.1.0.
开始查找原因
1、因为是使用了gulp-inject,先运行一个没有注入的指令试试。
运行clean
gulp.task('clean', function () { del(['build/*.*']); });
运行css
gulp.task('css', function () { return gulp.src('./src/**/*.less') .pipe(less()) //.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4')) //.pipe(gulp.dest('./styles')) .pipe(rename({suffix: '.min'})) .pipe(minifycss()) .pipe(gulp.dest('dist/css')) .pipe(livereload()) .pipe(notify({message: 'css task complete'})); });
也没有问题,看来就是gulp-inject引起的node报错了。
搜索度娘,没找到。
先屏蔽inject中的内容,没有问题。挨个看src,发现是由于某些js文件没有按照AngularJS的语法编写造成的,排除这些js文件,改为手工写死到index.html中,只注入符合语法的文件。注入通过。