如果我运行gulp命令,会出现上述错误。 我运行gulp命令时,我不知道代码中发生了什么。
module.js :339
throw err;
^
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> (E:\Project\wamp\www\gulpTest\node_modules\laravel-elixir\node_modules\gulp-notify\lib\extra_api.js:1:77)
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)
Gulpfile.js
var gulp = require('gulp'),
less = require('gulp-less'),
sass = require('gulp-sass'),
minify = require('gulp-minify-css'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
notify = require('gulp-notify'),
growl = require('gulp-notify-growl'),
phpunit = require('gulp-phpunit');
var paths = {
'dev': {
'less': './resources/assets/less/',
'js': './resources/assets/js/',
'vendor': './resources/assets/vendor/'
},
'production': {
'css': './public/assets/css/',
'js': './public/assets/js/'
}
};
/*
|--------------------------------------------------------------------------
| Elixir Asset Management
|--------------------------------------------------------------------------
|
| Elixir provides a clean, fluent API for defining some basic Gulp tasks
| for your Laravel application. By default, we are compiling the Less
| file for our application, as well as publishing vendor resources.
|
*/
// CSS
gulp.task('css', function() {
return gulp.src(paths.dev.less+'app.less')
.pipe(less())
.pipe(gulp.dest(paths.production.css))
.pipe(minify({keepSpecialComments:0}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.production.css));
});
// JS
gulp.task('js', function(){
return gulp.src([
paths.dev.vendor+'jquery/dist/jquery.js',
paths.dev.vendor+'bootstrap/dist/js/bootstrap.js',
paths.dev.js+'js'
])
.pipe(concat('app.min.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.production.js));
});
// PHP Unit
gulp.task('phpunit', function() {
var options = {debug: false, notify: true};
return gulp.src('./tests/*.php')
.pipe(phpunit('./vendor/bin/phpunit', options))
.on('error', notify.onError({
title: 'PHPUnit Failed',
message: 'One or more tests failed.'
}))
.pipe(notify({
title: 'PHPUnit Passed',
message: 'All tests passed!'
}));
});
gulp.task('watch', function() {
gulp.watch(paths.dev.less + '/*.less', ['css']);
gulp.watch(paths.dev.js + '/*.js', ['js']);
gulp.watch('./tests/*.php', ['phpunit']);
});
gulp.task('default', ['css', 'js', 'phpunit', 'watch']);
以上是gulp文件。 如果我使用elixir只显示问题。以上是gulp文件。 如果我使用elixir只显示问题。以上是gulp文件。 如果我用elixir只是为了显示问题。
答案 0 :(得分:1)
首先应确保through2
中有package.json
。如果不是,请运行npm --save-dev through2
。
如果它在package.json
运行npm install
中,请确保其被拉入。
如果已安装,请检查gulpfile.js
中是否有require('through2')
。