@@ -55,7 +55,7 @@ function resolvePackageImports (specifier, fromUrl) {
55
55
56
56
// Look for path inside packageJson
57
57
let resolvedPath
58
- if ( typeof imports == ' object') {
58
+ if ( Object . prototype . toString . call ( imports ) === '[ object Object] ') {
59
59
const requireSpecifier = imports . require
60
60
const importSpecifier = imports . import
61
61
// look for the possibility of require and import which is standard for CJS/ESM
@@ -65,12 +65,12 @@ function resolvePackageImports (specifier, fromUrl) {
65
65
} else if ( imports . node || imports . default ) {
66
66
resolvedPath = imports . node || imports . default
67
67
}
68
- } else if ( typeof imports == 'string' ) {
68
+ } else if ( typeof imports === 'string' ) {
69
69
resolvedPath = imports
70
70
}
71
71
72
- if ( existsSync ( resolvedPath ) ) {
73
- return resolvedPath
72
+ if ( resolvedPath ) {
73
+ return pathToFileURL ( require . resolve ( resolvedPath , { paths : [ dirname ( fileURLToPath ( fromUrl ) ) ] } ) ) . href
74
74
}
75
75
}
76
76
// return if we find a package.json but did not find an import
@@ -108,16 +108,16 @@ async function getCjsExports (url, context, parentLoad, source) {
108
108
let newUrl
109
109
// Entries in the import field should always start with #
110
110
if ( re . startsWith ( '#' ) ) {
111
- re = resolvePackageImports ( re , url )
112
- if ( ! re ) {
111
+ newUrl = resolvePackageImports ( re , url )
112
+ if ( ! newUrl ) {
113
113
// Unable to resolve specifier import
114
114
return
115
115
}
116
+ } else {
117
+ // Resolve the re-exported module relative to the current module.
118
+ newUrl = pathToFileURL ( require . resolve ( re , { paths : [ dirname ( fileURLToPath ( url ) ) ] } ) ) . href
116
119
}
117
120
118
- // Resolve the re-exported module relative to the current module.
119
- newUrl = pathToFileURL ( require . resolve ( re , { paths : [ dirname ( fileURLToPath ( url ) ) ] } ) ) . href
120
-
121
121
if ( newUrl . endsWith ( '.node' ) || newUrl . endsWith ( '.json' ) ) {
122
122
return
123
123
}
0 commit comments