diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 11ddef4bf88232..3b30c51a6f304e 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -1214,8 +1214,8 @@ Module._resolveFilename = function(request, parent, isMain, options) { if (request[0] === '#' && (parent?.filename || parent?.id === '')) { const parentPath = parent?.filename ?? process.cwd() + path.sep; - const pkg = packageJsonReader.getNearestParentPackageJSON(parentPath) || { __proto__: null }; - if (pkg.data?.imports != null) { + const pkg = packageJsonReader.getNearestParentPackageJSON(parentPath); + if (pkg?.data.imports != null) { try { const { packageImportsResolve } = require('internal/modules/esm/resolve'); return finalizeEsmResolution(