Search code examples
gruntjsgrunt-contrib-watch

Loading "gruntfile.js" tasks...ERROR >> SyntaxError: Unexpected identifier Warning: Task "default" not found. Use --force to continue


This is my gruntfile.js

module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.initConfig({
uglify:{
my_target: {
files:{
'_/js/script.js': ['_/components/js/*.js']      
}//files
}//myTarget
},//uglify
compass: {
dev:{
options: {
config: 'config.rb',                    
}//options
}//dev
},//compass
watch: {
options: {livereload: true},
scripts: {
files: ['_/components/js/*.js'],
tasks: ['uglify']       
},//scripts     
html: {
files: ['*.html']
},//html
sass: {
files: ['_/components/sass/*.scss']
tasks: ['compass:dev']
},//sass  
}//watch
})//initConfig
grunt.registerTask('default','watch'); 
}//exports

Running grunt in Command Prompt gives ERROR: Loading "gruntfile.js" tasks...ERROR >> SyntaxError: Unexpected identifier Warning: Task "default" not found. Use --force to continue.

When I comment out SASS block (in gruntfile.js)... then grunt says: Running "watch" task Waiting ... and everything is working fine!

Does anyone know what could be a problem?


Solution

  • To me there just seemed to be a few simple typo's, missing ,'s etc Also, try register a task like this:

    grunt.registerTask('default', ['watch']);
    

    here is a tidied up version, hopefully this works for you.

    module.exports = function(grunt) {
    
        grunt.initConfig({
            uglify: {
                my_target: {
                    files: {
                        '_/js/script.js': ['_/components/js/*.js']
                    } //files
                } //myTarget
            }, //uglify
            compass: {
                dev: {
                    options: {
                        config: 'config.rb'
                    } //options
                } //dev
            }, //compass
            watch: {
                options: {
                    livereload: true
                },
                scripts: {
                    files: ['_/components/js/*.js'],
                    tasks: ['uglify']
                }, //scripts     
                html: {
                    files: ['*.html']
                }, //html
                sass: {
                    files: ['_/components/sass/*.scss'],
                    tasks: ['compass:dev']
                } //sass  
            } //watch
        }); 
        //initConfig
        grunt.loadNpmTasks('grunt-contrib-uglify');
        grunt.loadNpmTasks('grunt-contrib-watch');
    
        grunt.registerTask('default', ['watch']);
    } //exports