天天看點

gulp建構前端檔案發生的錯誤:node:17232

今天想幫着同僚把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/*.*']);
});      
gulp建構前端檔案發生的錯誤:node:17232

運作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建構前端檔案發生的錯誤:node:17232

也沒有問題,看來就是gulp-inject引起的node報錯了。

搜尋度娘,沒找到。

先屏蔽inject中的内容,沒有問題。挨個看src,發現是由于某些js檔案沒有按照AngularJS的文法編寫造成的,排除這些js檔案,改為手工寫死到index.html中,隻注入符合文法的檔案。注入通過。

繼續閱讀