Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

throw new TypeError('callback provided to sync glob')?

Detail of error on execution:

# node 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)

I'm using glob 5.0.14 to start meanjs app.

This is my 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:

  config.getGlobbedFiles('./Rutas/*.js').forEach(function(routePath) {
    require(path.resolve(routePath))(app);
  });
like image 529
Guillermo Rodriguez Avatar asked Jul 21 '15 00:07

Guillermo Rodriguez


1 Answers

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);
        }
        ...
like image 107
mido Avatar answered Nov 09 '22 19:11

mido