简体   繁体   中英

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. The problem is, when my gulp build runs I get:

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 :

{
  "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:

节点模块文件夹

I've tried doing an rm -rf ./node_modules to clear it out and then followed by npm install to load fresh copies. 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:

/**
 * 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. If I comment out the task and comment the require for gulp-jasmin , it will require the other modules without a hitch.

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?

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):

Error: Cannot find module 'gulp-jasmin'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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