Javascript Gulp 错误:找不到模块“jshint/src/cli”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33984558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:45:08  来源:igfitidea点击:

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

javascriptterminalgulpjshint

提问by lateralaus

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

因此,我重新安装了 El Capitan,并让这些任务运行器再试一次。

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

我正在关注sitepoint 对 Gulp.js 的介绍,但我被困在第四步,当我尝试运行时,gulp jshint我得到“ 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

运行 gulp jshint 时出现终端错误

Folder structer for gulp project

gulp 项目的文件夹构造器

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

与往常一样,我永远感谢任何建议。

回答by fmatar

You need to install jshintas well, that will sort out the issue.

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

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

回答by lateralaus

It turns out I need to use npm install --save-dev jshint gulp-jshintinstead of npm install gulp-jshint --save-devas the tutorial stated. Discussion around this was found at https://github.com/spalger/gulp-jshint/issues/131with massive thanks to @user3042437 for suppling the link.

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

回答by Ben Erwin

If you still get the error after you put in the correct syntax above, (npm install --save-dev jshint gulp-jshint), which works.

如果在输入上面正确的语法后仍然出现错误,(npm install --save-dev jshint gulp-jshint),这是有效的。

Before you run the install again, go into your package.json file and remove the lines for jshint and gulp-jshint before you run the install, make sure you edit you package.json to remove the lines that call jshint and gulp-jshint, otherwise, the error will persist.

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

回答by Cengkuru Michael

Sometimes the order of the phrasing does matter. I found out that this npm install --save-dev jshint gulp-jshintdoes not work but this npm install jshint gulp-jshint --saveworks

有时,措辞的顺序确实很重要。我发现这 npm install --save-dev jshint gulp-jshint行不通,但这npm install jshint gulp-jshint --save行得通

回答by onyxglock

Here you target jshint, which you probably didn't install. (You do this in gulp.task('jshint', function() {.)

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

Try this:

尝试这个:

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

This matches the way you required it.

这与你的方式相匹配require

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

回答by Pushp Singh

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.

有一个绕过此错误的临时解决方案。如果您不想在应用程序中的任何地方使用 jshint.js 文件,即使这个临时解决方案也能正常工作。

  1. Go to your gulpfile.js file.
  2. Comment the code in line number 4.

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

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

    var jshint = require('gulp-jshint');
    
  3. 现在,在终端中运行 gulp 命令。您的服务器将启动。