gulpjs / gulp

A toolkit to automate & enhance your workflow
https://gulpjs.com
MIT License
33.01k stars 4.23k forks source link

Cannot find module 'through2' #1478

Closed rollrodrig closed 8 years ago

rollrodrig commented 8 years ago

Hello. I am working in Mac (capitan) and when i run gulp it show an console error it only happens in a fresh gulp project

I reinstalled my project and created again many times.

Error: Cannot find module 'through2'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Applications/MAMP/htdocs/landing-devito-joven/node_modules/gulp-sass/index.js:4:15)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
MacBook-Pro-de-Interbank:landing-devito-joven interbank$ gulp
module.js:339
    throw err;
    ^

packaje.js

{
  "name": "landing-devito-joven",
  "version": "1.0.0",
  "description": "Hola 2",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bootstrap-sass": "^3.3.5",
    "gulp": "^3.9.0",
    "gulp-concat": "^2.6.0",
    "gulp-jade": "^1.1.0",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^2.1.0",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-util": "^3.0.7",
    "gulp-watch": "^4.3.5",
    "gulp.spritesmith": "^4.2.2",
    "jquery": "^2.1.4"
  },
  "devDependencies": {}
}

gulpfile.js

var gulp = require('gulp');
var gutil = require('gulp-util');
var sass = require('gulp-sass');
var jade = require('gulp-jade');
var sourcemaps = require('gulp-sourcemaps');
var spritesmith = require('gulp.spritesmith');
var concat = require('gulp-concat');
var watch = require('gulp-watch');

var csslibs=[
  // './src/libs/css/owl.carousel.css'
]
//  Css libs
gulp.task('csslibs', function () {
  gulp.src('./src/sass/libs.scss')
    .pipe(sourcemaps.init())
    .pipe(sass().on('error', sass.logError))
    .pipe(sourcemaps.write('./maps'))
    .pipe(gulp.dest('./dist/assets/css/'));
});

//  Js libs
var jslibs = [
  'node_modules/jquery/dist/jquery.min.js',
  // './src/libs/js/owl.carousel.js'

]
gulp.task('jslibs', function () {
  gulp.src(jslibs)
  .pipe(concat('libs.js'))
  .pipe(gulp.dest('./dist/assets/js/'));
});

//  Js Concat
var jsFilesToConcat = [
  './dist/assets/js/libs.js',
  './dist/assets/js/main.js'
]
gulp.task('concatJs', function () {
  gulp.src(jsFilesToConcat)
  .pipe(concat('init.js'))
  .pipe(gulp.dest('./dist/assets/js/'));
});

// Css Concat
var cssFilesToConcat = [
  './dist/assets/css/libs.css',
  './dist/assets/css/main.css'
]
gulp.task('concatCss', function () {
  gulp.src(cssFilesToConcat)
  .pipe(concat('style.css'))
  .pipe(gulp.dest('./dist/assets/css/'));
});

// Sass
gulp.task('sass', function () {
  gulp.src('./src/sass/main.scss')
    .pipe(sourcemaps.init())
    .pipe(sass().on('error', sass.logError))
    .pipe(sourcemaps.write('./maps'))
    .pipe(gulp.dest('./dist/assets/css/'));
});

// Jade
gulp.task('jade', function() {
  gulp.src(['./src/jade/**/*.jade','!./src/jade/**/_*.jade'])
    .pipe(jade({
        pretty: true
    }))
    .on('error', function () { console.log(arguments); })
    .pipe(gulp.dest('./dist/'))
});

gulp.task('sprite', function () {
    var spriteData = gulp.src('./src/images/*.*')
                    .pipe(spritesmith({
                        imgName: 'sprite.png',
                        cssName: '_sprite.scss',
              imgPath:'../images/sprite.png',
              padding:10
    }));

    spriteData.img.pipe(gulp.dest('./dist/assets/images'))
    spriteData.css.pipe(gulp.dest('./src/sass/atoms/'));
});

// // Watch
gulp.task('watch', function () {
    watch('./src/sass/**/*.scss', function(event) {
      gulp.start('sass');
    });
    watch('./src/jade/**/*.jade', function(event) {
      gulp.start('jade');
    });

    watch(['./dist/assets/css/libs.css','./dist/assets/css/main.css'], function(event) {
      gulp.start('concatCss');
    });

});

gulp.task('default', ['sass', 'jade','watch']);
Romanx commented 8 years ago

gulp-sass requires through2 which hasn't seem to have installed properly. This isn't a gulp issue it's an NPM issue. Try clearing your node modules and trying again.

Also for future reference, github is used primarily as an issue tracker for the gulp team and not for user support, stack overflow is the best place for these things.

rollrodrig commented 8 years ago

I am intalling module per module again. I think it was a gulp bug in capitan -_-

rollrodrig commented 8 years ago

I just copies the same package.js from other project to avoid install package per package again

phated commented 8 years ago

Problem with your npm.