使用Gulp运行stubby4node时出错

时间:2016-11-28 02:54:41

标签: gulp

我正在尝试在JavaScript环境中设置Stubby Server,我收到以下错误。

我的Gulpfile的相关部分:

gulp.task('stubby', function(cb) {
    var options = {
        callback: function (server, options) {
            server.get(1, function (err, endpoint) {
                if (!err)
                    console.log(endpoint);
            });
        },
        stubs: 8000,
        tls: 8443,
        admin: 8010,
        files: [
            '*.*'
        ]
    };
    stubby(options, cb);
});

错误:

[12:15:03] Starting 'stubby'...
[12:15:03] 'stubby' errored after 17 ms
[12:15:03] Error: Missing error message
    at new PluginError (C:\Users\admin\IdeaProjects\myproject\node_modules\gulp-util\lib\PluginError.js:73:28)
    at readJSON (C:\Users\admin\IdeaProjects\myproject\node_modules\gulp-stubby-server\index.js:90:15)
    at C:\Users\admin\IdeaProjects\myproject\node_modules\gulp-stubby-server\index.js:149:24
    at Array.map (native)
    at stubbyPlugin (C:\Users\admin\IdeaProjects\myproject\node_modules\gulp-stubby-server\index.js:136:12)
    at Gulp.<anonymous> (C:\Users\admin\IdeaProjects\myproject\gulpfile.js:54:5)
    at module.exports (C:\Users\admin\IdeaProjects\myproject\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\Users\admin\IdeaProjects\myproject\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\Users\admin\IdeaProjects\myproject\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\Users\admin\IdeaProjects\myproject\node_modules\orchestrator\index.js:134:8)

1 个答案:

答案 0 :(得分:2)

Searching the gulp-stubby-server codebase for PluginError yields the follow snippet:

function readJSON(filepath, options) {
    var src = fs.readFileSync(filepath, options),
        result;
    if (!options.mute) {
        gutil.log(gutil.colors.yellow('Parsing ' + filepath + '...'));
    }
    try {
        result = JSON.parse(src);
        return result;
    } catch (e) {
        throw new gutil.PluginError(PLUGIN_NAME, 'Unable to parse "' + filepath + '" file (' + e.message + ').', e);
    }
}

- Source on GitHub

你可以说这是可能的罪魁祸首,因为你看到了堆栈跟踪,PluginError来自readJSON

问题

记下catch块。这是由与您的glob(*.*)匹配的文件之一不是有效的JSON文件引起的。

修复

  1. 确保您使用的是最新版本的gulp-stubby-server
  2. 确保您使用正确的glob(即,您的意思是*.*
  3. 确保当前工作目录中的所有文件都是有效的JSON文件