简体   繁体   English

Gulp要求“找不到模块”,即使它存在

[英]Gulp require “Cannot Find Module” even though it exists

I've encountered a strange issue and I'm running out of ideas to try. 我遇到了一个奇怪的问题,我的想法已经用完了。 I'm trying to learn JS unit testing, so am setting up gulp with Jasmine. 我正在尝试学习JS单元测试,所以我用Jasmine设置了gulp。 The problem is, when my gulp build runs I get: 问题是,当我的gulp构建运行时,我得到:

Error: Cannot find module 'gulp-jasmin'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/path/to/project/gulpfile.js:5:19)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)

Now, I know this is a common issue, but I've tried everything that typically resolves these. 现在,我知道这是一个常见问题,但我已经尝试了通常可以解决这些问题的一切。 My package.json : 我的package.json

{
  "name": "boxfish",
  "version": "0.3.0",
  "devDependencies": {
    "gulp": "^3.9.0",
    "gulp-jasmine": "^2.0.1",
    "gulp-livereload": "^3.8.0",
    "gulp-notify": "^2.2.0",
    "gulp-uglify": "^1.2.0"
  }
}

And my ./node_modules folder: 还有我的./node_modules文件夹:

节点模块文件夹

I've tried doing an rm -rf ./node_modules to clear it out and then followed by npm install to load fresh copies. 我已经尝试过rm -rf ./node_modules来清除它,然后是npm install来加载新的副本。 I can clearly see module their, and all the other modules load just fine, it's just this one. 我可以清楚地看到他们的模块,所有其他模块加载得很好,就是这一个。

My gulpfile.js looks like this: 我的gulpfile.js看起来像这样:

/**
 * Dependencies
 *****************/
var gulp        = require('gulp');
var jasmine     = require('gulp-jasmin');
var notify      = require('gulp-notify');

/**
 * Unit Testing
 *****************/

gulp.task('test', function () {
  gulp.src('./tests/*.js')
    .pipe(jasmine())
    .on('error', notify.onError({
      title: 'Jasmine Test Failed',
      message: 'One or more tests failed, see the cli for details.'
    }));
});

When I run gulp test , I get the missing module error. 当我运行gulp test ,我得到了丢失的模块错误。 If I comment out the task and comment the require for gulp-jasmin , it will require the other modules without a hitch. 如果我注释掉任务并评论gulp-jasmin的要求,那么它将需要其他模块。

Any ideas what I can do to get it to recognize this module ? 有什么想法可以让它识别这个模块吗? Is there some sort of autoload or registration that it is suppose to do with npm that I can check? 是否有某种自动加载注册 ,我想可以检查npm吗?

Are you positive it's not just a typo? 你是肯定的,这不仅仅是一个错字吗? Both your gulpfile and the error make it look like you mistyped gulp-jasmine (missing the 'e' on the end): 你的gulpfile和错误都让你看起来像你输错了gulp-jasmine(最后错过了'e'):

Error: Cannot find module 'gulp-jasmin'

var jasmine     = require('gulp-jasmin');

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

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