Grunt watch plugin does not display UglifyJS abort message

Problem

grunt-contrib-watch plugin provides nice auto-build feature but in some occasions does not display warning message from tasks, here is my grunt.js:

    min: {
        app: {
            src: [
                'some.js',
            ],
            dest: 'some.min.js'
        },
    }

    watch: {
        app: {
            files: 'some.js',
            tasks: ['min:app']
        },
    }

if source is fine, that everything goes smoothly; however when UglifyJS aborts:

run grunt min:app directly

Running "min:app" (min) task
Minifying with UglifyJS...ERROR
[L360:C46] Unexpected token name, expected punc (position: 8529)
<WARN> UglifyJS found errors. Use --force to continue. </WARN>

Aborted due to warnings.

auto-build via watch plugin

Waiting...OK
>> File "some.js" changed.
Running "min:app" (min) task

so there is no way to know if build is successful without looking at output itself.

similar setup with css less does display error to CLI, I am wondering if there is something I need to pass to grunt/watch plugin/uglify to makes it work?

Problem courtesy of: bitinn

Solution

Looks like Grunt v0.3.x + grunt-contrib-watch v0.1.4 is indeed the problem...

https://github.com/gruntjs/grunt-contrib-watch/issues/19

https://github.com/gruntjs/grunt-contrib-watch/issues/7

(EDIT: after upgrading to Grunt v0.4.x + grunt-contrib-watch v0.2.x, issue is resolved; though I should note this is a breaking upgrade, most v0.3 plugins are not converted to support Grunt v0.4 yet)

I closed my ticket on their repo as well, for reference: https://github.com/gruntjs/grunt-contrib-watch/issues/51

Solution courtesy of: bitinn

Discussion

Watch used jshint, and you need to make sure jshint is configured properly, then added to your grunt tasks for the watch command. Add the jshint task to your watch tasks, and also include a config options for jshint (example below):

 jshint: {
   all: [
    'Gruntfile.js',
    'some.js'
  ],
  options: {
    jshintrc: '.jshintrc'
  }
},
// minification options here
watch: {
  scripts: {
    files: 'some.js',
    tasks: ['jshint']

 }
}
Discussion courtesy of: Brian Vanderbusch

This recipe can be found in it's original form on Stack Over Flow.