运行grunt jshint时无法找到模块挂钩

时间:2015-09-17 14:55:33

标签: gruntjs runtime-error grunt-contrib-jshint

当我在cmd中运行grunt jshint时,请显示以下错误:

Loading "jshint.js" tasks...ERROR
Error: Cannot find module 'hooker
Warning: Task "jshint:myFiles" not found. Use --force to continue.
Aborted due to warnings.`

这是我的代码:

module.exports = function (grunt) {
grunt.initConfig({

// define source files and their destinations
uglify: {
   min: {
        files: grunt.file.expandMapping(['vendors/**/**/*.js','!vendors/**/**/*.min.js'], '', {
            rename: function(destBase, destPath) {
                return destBase+destPath.replace('.js', '.min.js');
            }
        })
    }
},
watch: {
    files:['vendors/**/**/*.min.js'],
    tasks: ['default']
},
clean: ["vendors"],
bower: {
    install: {
       //just run 'grunt bower:install' and you'll see files from your Bower packages in lib directory 
    }
},
jshint: {
  // You get to make the name
  // The paths tell JSHint which files to validate
  myFiles: ['gruntfile.js']
},
cssmin:{
    target: {
        files: grunt.file.expandMapping(['vendors/**/**/*.css','!vendors/**/**/*.min.css'], '', {
            rename: function(destBase, destPath) {
                return destBase+destPath.replace('.css', '.min.css','');
            }
        })
    }
},
});

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-bower-installer');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-watch-github');

// register at least this one task
grunt.registerTask('default', [ 'jshint','uglify','cssmin' ]);


};

我安装了这些插件:

  

{     " name":" my-project-name",     "版本":" 1.0.0",     " devDependencies":{       " grunt":" ~0.4.2",       " grunt-bower-installer":" ^ 0.3.6",       " grunt-contrib-clean":" ^ 0.6.0",       " grunt-contrib-compass":" ^ 1.0.3",       " grunt-contrib-cssmin":" ^ 0.14.0",       " grunt-contrib-imagemin":" ^ 0.9.4",       " grunt-contrib-jshint":" ^ 0.11.3",       " grunt-contrib-uglify":" ~0.2.4",       " grunt-contrib-watch":" ~0.5.3",       " grunt-watch-github":" ^ 0.1.1",       " jshint-stylish":" ^ 2.0.1"     }   }

1 个答案:

答案 0 :(得分:1)

我再次解决了安装jshint模块的问题。因为jshint安装不正确

npm install grunt-contrib-jshint --save-dev