gpt4 book ai didi

javascript - 抛出新的 TypeError ('callback provided to sync glob' )?

转载 作者:数据小太阳 更新时间:2023-10-29 05:05:34 27 4
gpt4 key购买 nike

执行错误详情:

# Node 应用程序.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('^(?:[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;
};

和 app.js 第 102 行:

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

最佳答案

就像我说的,您正在将回调参数传递给同步调用,将其更改为异步工作或删除回调参数:

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

关于javascript - 抛出新的 TypeError ('callback provided to sync glob' )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31528544/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com