Skip to content

Commit e045900

Browse files
committed
module: also enable subpath imports in REPL
1 parent 028a0a3 commit e045900

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
@@ -906,20 +906,19 @@ Module._resolveFilename = function(request, parent, isMain, options) {
906906
paths = Module._resolveLookupPaths(request, parent);
907907
}
908908

909-
if (parent?.filename) {
910-
if (request[0] === '#') {
911-
const pkg = readPackageScope(parent.filename) || {};
912-
if (pkg.data?.imports != null) {
913-
try {
914-
return finalizeEsmResolution(
915-
packageImportsResolve(request, pathToFileURL(parent.filename),
916-
cjsConditions), parent.filename,
917-
pkg.path);
918-
} catch (e) {
919-
if (e.code === 'ERR_MODULE_NOT_FOUND')
920-
throw createEsmNotFoundErr(request);
921-
throw e;
922-
}
909+
if (request[0] === '#' && (parent?.filename || parent?.id === '<repl>')) {
910+
const parentPath = parent?.filename ?? process.cwd() + path.sep;
911+
const pkg = readPackageScope(parentPath) || {};
912+
if (pkg.data?.imports != null) {
913+
try {
914+
return finalizeEsmResolution(
915+
packageImportsResolve(request, pathToFileURL(parentPath),
916+
cjsConditions), parentPath,
917+
pkg.path);
918+
} catch (e) {
919+
if (e.code === 'ERR_MODULE_NOT_FOUND')
920+
throw createEsmNotFoundErr(request);
921+
throw e;
923922
}
924923
}
925924
}

0 commit comments

Comments
 (0)