首页 > 代码库 > Gulp Error: Cannot find module 'jshint/src/cli'

Gulp Error: Cannot find module 'jshint/src/cli'

jshint是用来检测JavaScript的语法错误的

jshint的安装语法:

npm install gulp-jshint --save-dev

这样安装后出现了一下问题:

module.js:442
    throw err;
    ^

Error: Cannot find module jshint/src/cli
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\gulpAvue\node_modules\gulp-jshint\src\extract.js:1:79)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)

解决方案是:

npm install jshint gulp-jshint --save-dev

然后在gulpfile.js中引入模块,执行任务就可以啦

var jshint = require(gulp-jshint);
gulp.task(‘jshint‘,function(){
return gulp.src(‘src/js/main.js‘)
.pipe(jshint())
.pipe(jshint.reporter(‘default‘))  //对代码进行检查
});

 

Gulp Error: Cannot find module 'jshint/src/cli'