【问题标题】:Setting Up Gulp - Cannot find module 'gulp'设置 Gulp - 找不到模块“gulp”
【发布时间】:2016-06-24 22:23:31
【问题描述】:

我是 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

错误:

【问题讨论】:

    标签: gulp


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      在你的 devDependencies 中安装 Gulp

      npm install --save-dev gulp
      

      转到您的目录,即

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

      然后按 Enter

      【讨论】:

        猜你喜欢
        • 2017-06-24
        • 1970-01-01
        • 1970-01-01
        • 2019-05-26
        • 2017-01-03
        • 2017-11-07
        • 2018-10-19
        • 1970-01-01
        相关资源
        最近更新 更多