Kagami / gulp-ng-annotate

:pushpin: Add angularjs dependency injection annotations with ng-annotate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in plugin 'gulp-ng-annotate': error: couldn't process source due to parse error

dmitriz opened this issue · comments

Got this stange error on this harmless code:

$('#input-region').focusout(
$scope.$apply();
);

events.js:72
throw er; // Unhandled 'error' event
^
[gulp] Error in plugin 'gulp-ng-annotate': error: couldn't process source due to parse error
Line 54: Unexpected token ;
at Transform._transform (/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-ng-annotate/index.js:23:26)
at Transform._read (/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at Transform._write (/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:238:10)
at writeOrBuffer (/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:228:5)
at Transform.Writable.write (/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:195:11)
at write (/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-changed/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:605:24)
at flow (/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-changed/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:614:7)
at Transform.pipeOnReadable (/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-changed/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:646:5)
at Transform.emit (events.js:92:17)

No error as soon as I remove ; after $scope.$apply();

Does the error occur if you run ng-annotate directly? E.g. $ node_modules/.bin/ng-annotate -a you-file.js
I think you should report this to the upstream.

I found the error!

But the actual confusion with the Gulp plugin is the error reporting.
It gives the Line number but not the file name!

Here is an example:

/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-jshint/node_modules/map-stream/index.js:103
        throw err
              ^
[gulp] Error in plugin 'gulp-ng-annotate': error: couldn't process source due to parse error
Line 354: Unexpected token )
    at Transform._transform (/Users/dmitrizaitsev/Dropbox/33hotels/node_modules/gulp-ng-annotate/index.js:23:26)

What would really help is to also show the file name, which is passed to the plugin.

I have lots of files that are sent there automatically with Gulp,
with the original upstream it is not so much a problem.

In fact, it shows lots of files (from the node module) but not the important one, where I have the JS error.

I've added filename to the error reporting. Check the latest commit in master.

I also have a similar problem.

[11:49:57] controller.js was reloaded.

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error in plugin 'gulp-ng-annotate'
controller/controller.js: error: couldn't process source due to parse error
Line 15: Unexpected identifier
    at Transform._transform (/Volumes/public/node_modules/gulp-ng-annotate/index.js:34:26)
    at Transform._read (/Volumes/public/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at Transform._write (/Volumes/public/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
    at doWrite (/Volumes/public/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)
    at writeOrBuffer (/Volumes/public/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5)
    at Transform.Writable.write (/Volumes/public/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11)
    at write (/Volumes/public/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/Volumes/public/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (/Volumes/public/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:664:5)
    at DestroyableTransform.emit (events.js:92:17)
    at emitReadable_ (/Volumes/public/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:448:10)
    at emitReadable (/Volumes/public/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:444:5)
    at readableAddChunk (/Volumes/public/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:187:9)

Gulp then interrupted. :(

gulp-ng-annotate: 0.3.5

That's not a ng-annotate or gulp-ng-annotate issue. Seems like you have incorrent JS syntax in controller/controller.js.

Thank you for your help!

but I did'nt understand..

I have the issue too: the error message is really misdirecting

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error in plugin 'gulp-ng-annotate'
js/app.js: error: couldn't process source due to parse error
Line 53582: Unexpected token ILLEGAL
    at Transform._transform (/home/cran/Documents/Projects/i-hate-farms/hippopogram/node_modules/gulp-ng-annotate/index.js:34:26)
    at Transform._read (/home/cran/Documents/Projects/i-hate-farms/hippopogram/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at Transform._write (/home/cran/Documents/Projects/i-hate-farms/hippopogram/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
    at doWrite (/home/cran/Documents/Projects/i-hate-farms/hippopogram/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)
    at writeOrBuffer (/home/cran/Documents/Projects/i-hate-farms/hippopogram/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5)
    at Transform.Writable.write (/home/cran/Documents/Projects/i-hate-farms/hippopogram/node_modules/gulp-ng-annotate/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11)
    at Stream.ondata (stream.js:51:26)
    at Stream.emit (events.js:95:17)
    at Stream.endStream (/home/cran/Documents/Projects/i-hate-farms/hippopogram/node_modules/gulp-usemin/node_modules/gulp-concat/index.js:90:10)
    at _end (/home/cran/Documents/Projects/i-hate-farms/hippopogram/node_modules/gulp-usemin/node_modules/gulp-concat/node_modules/through/index.js:65:9)
make: *** [build] Error 8

What's wrong with this error message? It says you have invalid code in js/app.js at line 53582. Also check out FAQ.

My js/app.js is only 40 lines long :)

And I reverted from a "know" working state. Could the error be in another file altogether? Like a controller?

Probably your gulp build setup concatenated a lot of source code into vinyl File object with the path js/app.js. Try to add e.g. gulp-tap plugin before the gulp-ng-annotate and check the files and their contents which get passed to the gulp-ng-annotate input.

Thanks for your help!

I don't know how to use gulp-tap
Maybe there is a way to disable the minification in the gulp task :

gulp.task('usemin', ['templates', 'enable-production'], function() {
  return gulp.src(['app/index.html', 'app/badbrowser.html'])
    .pipe($.usemin({
      html: [$.minifyHtml({empty: true})],
      js: ['concat', $.ngAnnotate(), $.uglify({outSourceMap: false})],
      css: ['concat', $.minifyCss({compatibility: true, keepBreaks: true})]
    }))
    .pipe(gulp.dest('dist'));
});

This is my first time with angular and gulp (I'm trying to fix errors in an existing application)

Try to remove $.ngAnnotate(), $.uglify({outSourceMap: false}) from the js target and check the resulting JS file at line 53582. I've never used gulp-usemin plugin though.

I've done what you adviced and I don't have the error anymore.

gulp.task('usemin', ['templates', 'enable-production'], function() {
  return gulp.src(['app/index.html', 'app/badbrowser.html'])  
    .pipe($.usemin({
      html: [$.minifyHtml({empty: true})],
      js: ['concat'],
      css: ['concat', $.minifyCss({compatibility: true, keepBreaks: true})]
    }))
    .pipe(gulp.dest('dist'));
});

Now if I add ng-annotate without the uglify, the faulty line the one marked below:

$templateCache.put("partials/mobile/video_modal.html","<div class=\"media_modal_bottom_panel_wrap\">\n  <div class=\"media_modal_bottom_panel\">\n    <div class=\"media_modal_bottom_actions pull-right\">\n      <a class=\"media_modal_action_btn\" ng-if=\"messageID\" ng-click=\"delete()\" title=\"{{\'media_modal_delete\' | i18n}}\">\n        <i class=\"media_modal_action_btn_delete\"></i>\n      </a>\n    </div>\n\n    <div class=\"media_modal_bottom_actions pull-left\">\n      <a class=\"media_modal_action_btn\" ng-if=\"messageID\" ng-click=\"forward()\"  title=\"{{\'media_modal_forward\' | i18n}}\">\n        <i class=\"media_modal_action_btn_forward\"></i>\n      </a>\n    </div>\n\n    <div class=\"media_modal_info_wrap\">\n      <a class=\"media_modal_author\" my-user-link=\"video.user_id\" user-watch=\"true\"></a>\n      <br/>\n      <span class=\"media_modal_date\" ng-bind=\"video.date | dateOrTime :true\"></span>\n    </div>\n\n  </div>\n</div>\n\n<div class=\"media_modal_top_panel_wrap\">\n  <div class=\"media_modal_top_panel\">\n    <div class=\"media_modal_top_actions pull-right\">\n      <a class=\"media_modal_action_btn\" ng-click=\"download()\" title=\"{{\'media_modal_download\' | i18n}}\">\n        <i class=\"media_modal_action_btn_download\"></i>\n      </a>\n    </div>\n    <div class=\"media_modal_top_actions pull-left\">\n      <a ng-click=\"$close()\" class=\"navbar-quick-media-back\">\n        <i class=\"icon icon-back\"></i>\n        <div class=\"navbar-quick-back-title\">\n          <h4 class=\"media_modal_title_wrap\" my-i18n=\"media_modal_video\"></h4>\n        </div>\n      </a>\n    </div>\n  </div>\n</div>\n\n<div class=\"modal-dialog\">\n  <div class=\"modal-content\">\n    <div my-modal-width=\"{{video.full.width}}\" class=\"media_modal_wrap video_modal_wrap\" my-vertical-position=\"0.5\">\n\n      <div class=\"modal-body\">\n\n        <div class=\"video_modal_image_wrap\" my-load-video video=\"video\"></div>\n\n      </div>\n\n    </div>\n  </div>\n</div>\n\n");
// FAULTY LINE
$templateCache.put("partials/mobile/welcome.html","");}]);video_modal_wrap\" my-vertical-position=\"0.5\">\n\n      <div class=\"modal-body\">\n\n        <div class=\"video_modal_image_wrap\" my-load-video video=\"video\"></div>\n\n      </div>\n\n    </div>\n  </div>\n</div>\n\n");
$templateCache.put("partials/mobile/welcome.html","");}]);
/*!
 * Webogram v0.4.2 - messaging web application for MTProto
 * https://github.com/zhukov/webogram
 * Copyright (C) 2014 Igor Zhukov <igor.beatle@gmail.com>
 * https://github.com/zhukov/webogram/blob/master/LICENSE
 */

'use strict';

/* EmojiHelper */

(function (global, emojis, categories, spritesheets) {

None of which I have changed.

I'll track this heisenbug on my own as I have the feeling that it is absolutely not related to plugin and maybe not even related to my code.

Looks like gulp-angular-templatecache artifacts or some other odd build error. Anyway, that's clearly a problem with your gulp build setup.

thanks!

love you guys, save me a lot of time D: incorrent JS syntax in my javascript D:

Just in case it helps anyone, I had a massive HTML file that was included in the project so was being concatenated in, and this was also causing the same error, as it seemed the file was too big.