Skip to content

Commit 4c6e28c

Browse files
committed
module: also enable subpath imports in REPL
1 parent 5a8440b commit 4c6e28c

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -900,20 +900,19 @@ Module._resolveFilename = function(request, parent, isMain, options) {
900900
paths = Module._resolveLookupPaths(request, parent);
901901
}
902902

903-
if (parent?.filename) {
904-
if (request[0] === '#') {
905-
const pkg = readPackageScope(parent.filename) || {};
906-
if (pkg.data?.imports != null) {
907-
try {
908-
return finalizeEsmResolution(
909-
packageImportsResolve(request, pathToFileURL(parent.filename),
910-
cjsConditions), parent.filename,
911-
pkg.path);
912-
} catch (e) {
913-
if (e.code === 'ERR_MODULE_NOT_FOUND')
914-
throw createEsmNotFoundErr(request);
915-
throw e;
916-
}
903+
if (request[0] === '#' && (parent?.filename || parent?.id === '<repl>')) {
904+
const parentPath = parent?.filename ?? process.cwd() + path.sep;
905+
const pkg = readPackageScope(parentPath) || {};
906+
if (pkg.data?.imports != null) {
907+
try {
908+
return finalizeEsmResolution(
909+
packageImportsResolve(request, pathToFileURL(parentPath),
910+
cjsConditions), parentPath,
911+
pkg.path);
912+
} catch (e) {
913+
if (e.code === 'ERR_MODULE_NOT_FOUND')
914+
throw createEsmNotFoundErr(request);
915+
throw e;
917916
}
918917
}
919918
}

0 commit comments

Comments
 (0)