设置Gulp - 找不到模块' gulp'

时间:2016-06-24 04:42:15

标签: gulp

我是Gulp的新手,正在关注tutorial。我进入最后一步并在我的项目文件中运行gulp,但是我收到一条错误消息,说明该模块“gulp'无法找到。我已经确认我安装了gulp。 CLI(侧面说明,CLI是什么意思?)和本地版本都是3.9.1。我想知道我做错了什么?

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

2 个答案:

答案 0 :(得分:0)

问题是因为我的项目文件夹名为'gulp'。将项目文件夹更改为除“gulp”以外的任何其他内容解决了该问题。 https://github.com/npm/npm/issues/11772

答案 1 :(得分:0)

在devDependencies中安装Gulp

npm install --save-dev gulp

转到您的DIrectory,

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

然后按Enter键