【问题标题】:Gulp.js can't compile angular.js project due to excessive js errors?Gulp.js 由于过多的 js 错误而无法编译 angular.js 项目?
【发布时间】:2014-06-23 02:38:51
【问题描述】:

我正在尝试从 Grunt 转移到 Gulp。这个项目在 Grunt 下运行良好,所以我一定是在 Gulp 中做错了。

除脚本外,所有其他任务都有效。我现在已经厌倦了添加和注释部分。

我不断收到与意外令牌有关的错误。使用 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)

将 ng-min 注释掉并使用 Uglify(默认):

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

我被难住了。任务如下:

// 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'
    }));
});

【问题讨论】:

  • 你的代码中有一些 try catch 吗?
  • 您使用的是什么版本的 ngmin
  • 不相关说明:您包含来自 angular-ui-bootstrap 的 2 个分发文件:“bower_components/angular-bootstrap/ui-bootstrap.min.js”和“bower_components/angular-bootstrap/ui- bootstrap-tpls.min.js" 不需要,只需要一个。检查更多:github.com/angular-ui/bootstrap#installation

标签: node.js angularjs gulp


【解决方案1】:

我认为可以肯定地说,两个插件的输出一起表明您在传递给 ngmin 或 uglify 的内容的第二行有语法错误。

这两个插件的反应稍有不同。一个是帮助你告诉你行号,另一个是帮助你告诉你文件名。

由于您已经重命名了文件,因此他们似乎在谈论已经缩小的文件,而实际上只是您过早地重命名了它的内存表示。

对于初学者,我建议您在缩小文件之前不要重命名文件,因为您的错误令人困惑。此时,您可能会看到错误出现在保存到 dist/scripts/main.js 的文件中(在该文件的第二行,您显然有一个错误的冒号)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    • 2021-12-03
    • 2020-08-07
    • 1970-01-01
    相关资源
    最近更新 更多