Skip to content

Instantly share code, notes, and snippets.

@kumavis
Created July 5, 2013 05:11
Show Gist options
  • Save kumavis/5931964 to your computer and use it in GitHub Desktop.
Save kumavis/5931964 to your computer and use it in GitHub Desktop.
Browserify blowing up
/usr/local/share/npm/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:91
var dir = path.resolve(x, pkg.main);
^
TypeError: Cannot read property 'main' of undefined
at /usr/local/share/npm/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:91:54
at load (/usr/local/share/npm/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:54:43)
at /usr/local/share/npm/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:60:22
at /usr/local/share/npm/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:16:47
at Object.oncomplete (fs.js:107:15)
@kumavis
Copy link
Author

kumavis commented Jul 5, 2013

loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) {   // callback takes 3 args, assumes pkg is present 
                        if (err) return cb(err);
                        if (m) return cb(null, m, pkg);
                        var dir = path.resolve(x, pkg.main);
                        loadAsDirectory(dir, pkg, function (err, n, pkg) {
                            if (err) return cb(err);
                            if (n) return cb(null, n, pkg);
                            loadAsFile(path.join(x, '/index'), pkg, cb);
                        });
                    });
function loadAsFile (x, pkg, cb) {
        if (typeof pkg === 'function') {
            cb = pkg;
            pkg = opts.package;
        }

        (function load (exts) {
            if (exts.length === 0) return cb(null, undefined);    // callback is called with 2 args, no pkg
            var file = x + exts[0];

            isFile(file, function (err, ex) {
                if (err) cb(err)
                else if (ex) cb(null, file, pkg)
                else load(exts.slice(1))
            });
        })([''].concat(extensions));
    }

@kumavis
Copy link
Author

kumavis commented Jul 5, 2013

changing
if (exts.length === 0) return cb(null, undefined);
to
if (exts.length === 0) return cb(null, undefined, pkg);
seems to have solved the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment