Skip to content

Commit dd88722

Browse files
authored
Avoid using baseUrl for relative imports (#1111)
1 parent 12cce12 commit dd88722

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/transpilation/resolve.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,15 @@ function resolveDependency(
167167
console.log(`Resolving "${dependency}" from ${normalizeSlashes(fileDirectory)}`);
168168
}
169169

170+
// Check if the import is relative
171+
const isRelative = ["/", "./", "../"].some(p => dependency.startsWith(p));
172+
173+
// If the import is relative, always resolve it relative to the requiring file
174+
// If the import is not relative, resolve it relative to options.baseUrl if it is set
175+
const relativeTo = isRelative ? fileDirectory : options.baseUrl ?? fileDirectory;
176+
170177
// Check if file is a file in the project
171-
const resolvedPath = path.join(options.baseUrl ?? fileDirectory, dependency);
178+
const resolvedPath = path.join(relativeTo, dependency);
172179

173180
const possibleProjectFiles = [
174181
resolvedPath, // JSON files need their extension as part of the import path, caught by this branch,

0 commit comments

Comments
 (0)