Detail of error on execution:
执行错误的详细信息:
# node app.jsthrow 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)
I'm using glob 5.0.14 to start meanjs app.
我正在使用glob 5.0.14来启动meanjs app。
This is my config.js:
这是我的config.js:
var _ = require('lodash'),
glob = require('glob');
module.exports.getGlobbedFiles = function(globPatterns, removeRoot) {
var _this = this;
var urlRegex = new RegExp('^(?:[a-z]+:)?\/\/', '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;
};
And app.js line 102:
和app.js第102行:
config.getGlobbedFiles('./Rutas/*.js').forEach(function(routePath) {
require(path.resolve(routePath))(app);
});
1 个解决方案
#1
11
Like I said, you are passing callback parameter to a synchrounous call, change it to either work async or, remove the callback parameter:
就像我说的那样,你将回调参数传递给同步调用,将其更改为工作异步,或者删除回调参数:
...
else {
var files = glob(globPatterns, { sync: true });
if (removeRoot) {
files = files.map(function(file) {
return file.replace(removeRoot, '');
});
}
output = _.union(output, files);
}
...
#1
11
Like I said, you are passing callback parameter to a synchrounous call, change it to either work async or, remove the callback parameter:
就像我说的那样,你将回调参数传递给同步调用,将其更改为工作异步,或者删除回调参数:
...
else {
var files = glob(globPatterns, { sync: true });
if (removeRoot) {
files = files.map(function(file) {
return file.replace(removeRoot, '');
});
}
output = _.union(output, files);
}
...