无法运行gulp任务

时间:2015-04-28 20:44:15

标签: gulp

我试图运行一个简单的gulp-sass任务,但我收到了这个错误:

[22:42:14] Starting 'sass'...
[22:42:14] Finished 'sass' after 10 ms

 events.js:72
    throw er; // Unhandled 'error' event
          ^
   Error: File not found with singular glob
at Glob.<anonymous> (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\index.js:34:30)
at Glob.EventEmitter.emit (events.js:95:17)
at Glob._finish (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:171:8)
at done (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:158:12)
at Glob._processSimple2 (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:640:12)
at D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:628:10
at Glob._stat2 (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:724:12)
at lstatcb_ (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:716:12)
at RES (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\node_modules\inflight\inflight.js:23:14)
at f (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\node_modules\once\once.js:17:25)

我在全局和本地安装gulp作为开发人员依赖。 这是我的任务:

var gulp = require("gulp"),
sass = require("gulp-sass");

gulp.task("sass", function(){
    gulp.src('assets/sass/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('assets/css'))
});

2 个答案:

答案 0 :(得分:0)

错误并不是那么清楚,就像Exception被错误的链接抛出一样(未找到资源)

答案 1 :(得分:0)

是的,这是正确的。只要找不到资源,就会抛出错误。我写了一个函数来防止在我的文件中出现这种情况。 运行“npm install fs --save”。 然后将其添加到您的gulpfile

var fs = require('fs');
var validateResources = function (resources) {
  resources.forEach(function (resource) {
    if (!fs.existsSync(resource)) {
      throw resource + " not found!";
    }
  });
};

有了这个,你在某种程度上是安全的。