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

So I've got a fresh install of El Capitan and I'm giving these task runners another go.

I'm following sitepoint's An introduction to Gulp.js, but I'm stuck on step four, when I try to run gulp jshint I get "Error: Cannot find module 'jshint/src/cli'"

I've no idea what's causing this, which is why I'm asking here. Below are a couple of screen grabs to help with the issue.

Terminal error when running gulp jshint

Folder structer for gulp project

As always, I'm eternally grateful for any advice.

55654 次浏览

您还需要安装 Jshint,这将解决问题。

> npm install --save-dev jshint gulp-jshint

事实证明,我需要使用 npm install --save-dev jshint gulp-jshint而不是 npm install gulp-jshint --save-dev,如教程所述。关于这个问题的讨论在 https://github.com/spalger/gulp-jshint/issues/131上发现,并且非常感谢@user3042437提供了这个链接。

Sometimes the order of the phrasing does matter. I found out that this npm install --save-dev jshint gulp-jshint不工作,但这个 npm install jshint gulp-jshint --save工作

在这里,您的目标是 jshint,可能没有安装它(在 gulp.task('jshint', function() {中执行此操作)

试试这个:

gulp.task('gulp-jshint', function() {

这个和你的 required 吻合。

var jshint = require('gulp-jshint');

如果在输入上面正确的语法之后仍然得到错误, (npm install —— save-dev jshint Gulp-jshint) ,它可以工作。

在再次运行安装之前,进入 package.json 文件,并在运行安装之前删除 jshint 和 Gulp-jshint 的行,确保编辑 package.json 以删除调用 jshint 和 Gulp-jshint 的行,否则,错误将持续存在。

There is a temporary solution for bypassing this error. Even this temporary solution will also work properly, if in case you don't want to use jshint.js file in you application anywhere.

  1. 转到 Gulpfile.js 文件。
  2. 注释第4行中的代码。

    var jshint = require('gulp-jshint');
    
  3. Now, run gulp command in your terminal. Your server will be up.