Skip to content

Commit

Permalink
[Fix] TypeError: Path must be a string. Received undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhaenisch authored and ljharb committed Jan 12, 2019
1 parent 3296106 commit ce163e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function resolve(x, options, callback) {
if (opts.preserveSymlinks === false) {
fs.realpath(absoluteStart, function (realPathErr, realStart) {
if (realPathErr && realPathErr.code !== 'ENOENT') cb(err);
else init(realStart);
else init(realPathErr ? absoluteStart : realStart);
});
} else {
init(absoluteStart);
Expand Down
18 changes: 17 additions & 1 deletion test/faulty_basedir.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var test = require('tape');
var path = require('path');
var resolve = require('../');

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

resolve('tape/lib/test.js', { basedir: resolverDir }, function (err, res, pkg) {
t.equal(true, !!err);
t.equal(!!err, true);
});
});

test('non-existent basedir should not throw when preserveSymlinks is false', function (t) {
t.plan(2);

var opts = {
basedir: path.join(path.sep, 'unreal', 'path', 'that', 'does', 'not', 'exist'),
preserveSymlinks: false
};

var module = './dotdot/abc';

resolve(module, opts, function (err, res) {
t.equal(err.code, 'MODULE_NOT_FOUND');
t.equal(res, undefined);
});
});

0 comments on commit ce163e3

Please sign in to comment.