在gulpjs真的很奇怪的行为

时间:2016-11-21 17:42:18

标签: node.js gulp

我有2个文件,一个gulp文件:

var gulp = require("gulp");
var babel = require("gulp‐babel");
var browserSync = require('browser‐sync');
var concat = require('gulp‐concat');
var eslint = require('gulp‐eslint');
var filter = require('gulp‐filter');
var newer = require('gulp‐newer');
var notify = require('gulp‐notify');
var plumber = require('gulp‐plumber');
var reload = browserSync.reload;
var less = require('gulp‐less');
var sourcemaps = require('gulp‐sourcemaps');



var onError = (err)=> {
    notify.onError({title: "Error",message: "<%= error %>",})(err);
    this.emit('end');
};

var plumberOptions = {errorHandler: onError};


gulp.task("test",()=>{

  onError("test error");

});

然后是一个包文件:

{
  "name": "testgulpfile",
  "version": "1.0.0",
  "main": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "browser-sync": "^2.18.2",
    "gulp": "^3.9.1",
    "gulp-autoprefixer": "^3.1.1",
    "gulp-babel": "^6.1.2",
    "gulp-concat": "^2.6.1",
    "gulp-eslint": "^3.0.1",
    "gulp-filter": "^4.0.0",
    "gulp-less": "^3.3.0",
    "gulp-newer": "^1.3.0",
    "gulp-notify": "^2.2.0",
    "gulp-plumber": "^1.1.0",
    "gulp-sourcemaps": "^2.2.0"
  }
}

问题在于,当我(显然我已经运行了npm install)启动“gulp test”或者只是从windows 10或linux ubuntu“gulp”时,会出现以下错误:

module.js 474

cannot find module 'gulp-babel' ...

我无法弄清楚这些文件有什么问题。

1 个答案:

答案 0 :(得分:1)

您遇到编码问题:

我用你的包裹名称做了这个:

// Package name typed by keyboard
> encodeURI('gulp-sourcemaps')
'gulp-sourcemaps'

// Package name copied from your code (from gulpfile)
> encodeURI('gulp‐sourcemaps')
'gulp%E2%80%90sourcemaps'

删除包名称&amp;从键盘输入它们 要么 只需删除' - '&amp;从键盘输入它将起作用。