简体   繁体   English

Gulp错误:找不到模块'jshint / src / cli'

[英]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. 所以我有一个新的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 jshint I 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. 下面是几个屏幕抓取来帮助解决这个问题。

运行gulp jshint时出现终端错误

gulp项目的文件夹结构

As always, I'm eternally grateful for any advice. 一如既往,我永远感激任何建议。

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

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

It turns out I need to use npm install --save-dev jshint gulp-jshint instead of npm install gulp-jshint --save-dev as the tutorial stated. 事实证明我需要使用npm install --save-dev jshint gulp-jshint而不是npm install gulp-jshint --save-dev作为教程说明。 Discussion around this was found at https://github.com/spalger/gulp-jshint/issues/131 with massive thanks to @user3042437 for suppling the link. 有关此问题的讨论发现于https://github.com/spalger/gulp-jshint/issues/131 ,非常感谢@ user3042437提供链接。

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的行,否则,错误将持续存在。

Sometimes the order of the phrasing does matter. 有时,短语的顺序很重要。 I found out that this npm install --save-dev jshint gulp-jshint does not work but this npm install jshint gulp-jshint --save works 我发现这个npm install --save-dev jshint gulp-jshint不起作用,但这个npm install jshint gulp-jshint --save工作原理

Here you target jshint , which you probably didn't install. 在这里你定位jshint ,你可能没有安装。 (You do this in gulp.task('jshint', function() { .) (你在gulp.task('jshint', function() {执行此gulp.task('jshint', function() { 。)

Try this: 试试这个:

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

This matches the way you require d it. 这符合您的require

var jshint = require('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. 即使这个临时解决方案也可以正常工作,如果您不想在任何地方使用jshint.js文件。

  1. Go to your gulpfile.js file. 转到您的gulpfile.js文件。
  2. Comment the code in line number 4. 在第4行注释代码。

     var jshint = require('gulp-jshint'); 
  3. Now, run gulp command in your terminal. 现在,在终端中运行gulp命令。 Your server will be up. 你的服务器将启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM