2016-06-24 75 views
0

我是Gulp的新手,我正在关注tutorial。我到了最后一步,在我的项目文件中运行gulp,但我收到一个错误消息,指出无法找到模块'gulp'。我已经验证了我已经安装了gulp。 CLI(在附注中,CLI是什么意思?)和本地版本都是3.9.1。我想知道我做错了什么?设置Gulp - 找不到模块'gulp'

gulpfile.js:

// Include gulp 
var gulp = require('gulp'); 

// Include Our Plugins 
var jshint = require('gulp-jshint'); 
var concat = require('gulp-concat'); 
var uglify = require('gulp-uglify'); 
var rename = require('gulp-rename'); 

// Lint Task 
gulp.task('lint', function() { 
    return gulp.src('js/*.js') 
     .pipe(jshint()) 
     .pipe(jshint.reporter('default')); 
}); 

// Concatenate & Minify JS 
gulp.task('scripts', function() { 
    return gulp.src('js/*.js') 
     .pipe(concat('all.js')) 
     .pipe(gulp.dest('dist')) 
     .pipe(rename('all.min.js')) 
     .pipe(uglify()) 
     .pipe(gulp.dest('dist/js')); 
}); 

// Watch Files For Changes 
gulp.task('watch', function() { 
    gulp.watch('js/*.js', ['lint', 'scripts']); 
}); 

// Default Task 
gulp.task('default', ['lint', 'scripts', 'watch']); 

的package.json:

{ 
    "name": "gulp", 
    "version": "3.9.1", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "author": "", 
    "license": "ISC", 
    "devDependencies": { 
    "gulp-concat": "^2.6.0", 
    "gulp-jshint": "^2.0.1", 
    "gulp-rename": "^1.2.2", 
    "gulp-uglify": "^1.5.4", 
    "jshint": "^2.9.2" 
    } 
} 

文件结构:

|-- gulpfile.js 
|-- package.json 
|-- node_modules 
| |-- .bin 
| |-- gulp-concat 
| |-- gulp-jshint 
| |-- gulp-rename 
| |-- gulp-uglify 
| |-- jshint 

错误:

command line gulp error

回答

0

在devDependencies安装咕嘟咕嘟

npm install --save-dev gulp 

去你的目录,这是

D:\xampp\htdocs\test\gulp>npm install --save-dev gulp 

并按下回车键