1

在下面运行 gulp 任务时,我从 JSmin 收到以下错误消息:

/var/www/html/a/node_modules/gulp-jsmin/node_modules/jsmin-sourcemap/node_modules/jsmin2/lib/jsmin.c.index.js:40
          stream.write(str);
                 ^
TypeError: Object function (err) {
          // Add the error to output
          options.error += err;
        } has no method 'write'
    at fputs (/var/www/html/a/node_modules/gulp-jsmin/node_modules/jsmin-sourcemap/node_modules/jsmin2/lib/jsmin.c.index.js:40:18)
    at error (/var/www/html/a/node_modules/gulp-jsmin/node_modules/jsmin-sourcemap/node_modules/jsmin2/lib/jsmin.c.index.js:89:9)
    at action (/var/www/html/a/node_modules/gulp-jsmin/node_modules/jsmin-sourcemap/node_modules/jsmin2/lib/jsmin.c.index.js:218:25)
    at jsmin (/var/www/html/a/node_modules/gulp-jsmin/node_modules/jsmin-sourcemap/node_modules/jsmin2/lib/jsmin.c.index.js:352:21)
    at main (/var/www/html/a/node_modules/gulp-jsmin/node_modules/jsmin-sourcemap/node_modules/jsmin2/lib/jsmin.c.index.js:368:9)
    at jsminFn (/var/www/html/a/node_modules/gulp-jsmin/node_modules/jsmin-sourcemap/node_modules/jsmin2/lib/jsmin.c.index.js:373:12)
    at jsmin (/var/www/html/a/node_modules/gulp-jsmin/node_modules/jsmin-sourcemap/node_modules/jsmin2/lib/jsmin.js:82:3)
    at Object.Collector.addFile (/var/www/html/a/node_modules/gulp-jsmin/node_modules/jsmin-sourcemap/lib/jsmin.sourcemap.js:24:19)
    at Array.forEach (native)
    at module.exports (/var/www/html/a/node_modules/gulp-jsmin/node_modules/jsmin-sourcemap/lib/jsmin.sourcemap.js:136:9)

/** Gulp 任务 **/

gulp.task('js', function() {
    gulp.src('app/assets/javascripts/**/*.js')
        .pipe(changed('public/assets/javascripts/min'))
        .pipe(jsmin())
        .pipe(rename({suffix: '.min'}))
        .pipe(gulp.dest('public/assets/javascripts/min'));

    gulp.src([  'public/assets/javascripts/min/bootstrap.min.js','public/assets/javascripts/min/jquery.flexslider.min.js','public/assets/javascripts/min/waypoints.min.min.js',
            'public/assets/javascripts/min/modernizr.custom.min.js','public/assets/javascripts/min/jquery.stapel.min.js', 'public/assets/javascripts/min/jquery.socialist.min.js',
            'public/assets/javascripts/min/enscroll.min.min.js','public/assets/javascripts/min/jquery-ui-1.8.2.custom.min.min.js','public/assets/javascripts/min/pirobox_extended_min.min.js',
            'public/assets/javascripts/min/jquery.masonry.min.min.js', 'public/assets/javascripts/min/functions.min.js'])
        .pipe(concat('application.js'))
        .pipe(gulp.dest('public/assets/javascripts/min/'));
});

有人可以帮我弄清楚发生了什么吗?

4

1 回答 1

0

简短的回答是该node-jsmin2模块中有一个错误,自修订版7d5f486f46b453d738057e97060e4805846bf4af以来引入。

在那个版本中,fputs被修改为 callstream.write(str)而不是stream(str),并且stdout被修改为包含writewriteFromIndex方法的对象——但stderr没有进行类似的修改。(顺便说一句,该提交意味着 and 的默认值stdoutstderrconsole.logand console.error,不再合适。这已TODO.md在该提交的更改中有所提及。)

这是一个快速的“修复”(我打算发送一个拉取请求,但决定不这样做):

diff --git a/lib/jsmin.js b/lib/jsmin.js
index 439957b..c6f9331 100644
--- a/lib/jsmin.js
+++ b/lib/jsmin.js
@@ -68,9 +68,11 @@ function jsmin(input) {
             output += char;
           }
         },
-        'stderr': function (err) {
-          // Add the error to output
-          options.error += err;
+        'stderr': {
+          'write': function (err) {
+            // Add the error to output
+            options.error += err;
+          }
         },
         'exit': function (code) {
           // Throw the collective error
于 2014-12-09T12:18:17.073 回答