Skip to content

Commit ce163e3

Browse files
simonhaenischljharb
authored andcommitted
[Fix] TypeError: Path must be a string. Received undefined
1 parent 3296106 commit ce163e3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = function resolve(x, options, callback) {
4646
if (opts.preserveSymlinks === false) {
4747
fs.realpath(absoluteStart, function (realPathErr, realStart) {
4848
if (realPathErr && realPathErr.code !== 'ENOENT') cb(err);
49-
else init(realStart);
49+
else init(realPathErr ? absoluteStart : realStart);
5050
});
5151
} else {
5252
init(absoluteStart);

test/faulty_basedir.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var test = require('tape');
2+
var path = require('path');
23
var resolve = require('../');
34

45
test('faulty basedir must produce error in windows', { skip: process.platform !== 'win32' }, function (t) {
@@ -7,7 +8,22 @@ test('faulty basedir must produce error in windows', { skip: process.platform !=
78
var resolverDir = 'C:\\a\\b\\c\\d';
89

910
resolve('tape/lib/test.js', { basedir: resolverDir }, function (err, res, pkg) {
10-
t.equal(true, !!err);
11+
t.equal(!!err, true);
1112
});
13+
});
14+
15+
test('non-existent basedir should not throw when preserveSymlinks is false', function (t) {
16+
t.plan(2);
17+
18+
var opts = {
19+
basedir: path.join(path.sep, 'unreal', 'path', 'that', 'does', 'not', 'exist'),
20+
preserveSymlinks: false
21+
};
1222

23+
var module = './dotdot/abc';
24+
25+
resolve(module, opts, function (err, res) {
26+
t.equal(err.code, 'MODULE_NOT_FOUND');
27+
t.equal(res, undefined);
28+
});
1329
});

0 commit comments

Comments
 (0)