znerol/node-browserify — comment on commit 94b01e292e3cffc6230d076b3c818ff18dbe8f86
File:  line 0
By znerol:

The code indeed looks identical when only looking at the patch. The fix lies within the fact that the original x is passed to path.resolve while base gets concatenated with /package.json and /index. Stripping trailing slashes is important in the latter case but is harmfull in the former, especially when x="/".

```javascript
function loadAsDirectorySync (x) {
var base = x.replace(/\/+$/, '');
var pkgfile = base + '/package.json';
if (require.modules[pkgfile]) {
var pkg = require.modules[pkgfile]();
var b = pkg.browserify;
if (typeof b === 'object' && b.main) {
var m = loadAsFileSync(path.resolve(x, b.main));
if (m) return m;
}
else if (typeof b === 'string') {
var m = loadAsFileSync(path.resolve(x, b));
if (m) return m;
}
else if (pkg.main) {
var m = loadAsFileSync(path.resolve(x, pkg.main));
if (m) return m;
}
}

return loadAsFileSync(base + '/index');
}
```