抛出新的TypeError('callback提供同步glob')?

执行错误的细节:

#节点app.js

throw new TypeError('callback provided to sync glob') ^ TypeError: callback provided to sync glob at glob (C:\Users\z\Documents\node_modules\glob\glob.js:70:13) at Object.module.exports.getGlobbedFiles (C:\Users\z\Documents\Server\Config\config.js:31:4) at Object.<anonymous> (C:\Users\z\Documents\Server\app.js:102:10) 

我使用glob 5.0.14来启动meanjs应用程序。

这是我的config.js:

  var _ = require('lodash'), glob = require('glob'); module.exports.getGlobbedFiles = function(globPatterns, removeRoot) { var _this = this; var urlRegex = new RegExp('^(?:[az]+:)?\/\/', 'i'); var output = []; if (_.isArray(globPatterns)) { globPatterns.forEach(function(globPattern) { output = _.union(output, _this.getGlobbedFiles(globPattern, removeRoot)); }); } else if (_.isString(globPatterns)) { if (urlRegex.test(globPatterns)) { output.push(globPatterns); } else { 31=> glob(globPatterns, { sync: true }, function(err, files) { if (removeRoot) { files = files.map(function(file) { return file.replace(removeRoot, ''); }); } output = _.union(output, files); }); } } return output; }; 

和app.js第102行:

  config.getGlobbedFiles('./Rutas/*.js').forEach(function(routePath) { require(path.resolve(routePath))(app); }); 

就像我所说的,你正在将callbackparameter passing给同步调用,将其更改为asynchronous工作或删除callback参数:

  ... else { var files = glob(globPatterns, { sync: true }); if (removeRoot) { files = files.map(function(file) { return file.replace(removeRoot, ''); }); } output = _.union(output, files); } ...