Skip to content

Commit 3e556a1

Browse files
Fix build with TS alias without basePath (#11693)
Closes #11686. I think this was accidentally introduced when [we removed `baseUrl` ](#9944). The change assumes rootDir as the fallback if there's no baseUrl (default TS behaviour).
1 parent cd4c8bc commit 3e556a1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

.changesets/11693.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Fix build with TS alias without basePath (#11693) by @callingmedic911
2+
3+
It fixes the build process for a project with TypeScript path alias. It uses root directory as the fallback if there's no baseUrl in `tsconfig.json`.

packages/babel-config/src/common.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,21 @@ export const getPathsFromTypeScriptConfig = (
140140
return {}
141141
}
142142

143-
if (!config.compilerOptions?.baseUrl || !config.compilerOptions?.paths) {
143+
if (!config.compilerOptions?.paths) {
144144
return {}
145145
}
146146

147147
const { baseUrl, paths } = config.compilerOptions
148148

149-
// Convert it to absolute path - on windows the baseUrl is already absolute
150-
const absoluteBase = path.isAbsolute(baseUrl)
151-
? baseUrl
152-
: path.join(rootDir, baseUrl)
149+
let absoluteBase: string
150+
if (baseUrl) {
151+
// Convert it to absolute path - on windows the baseUrl is already absolute
152+
absoluteBase = path.isAbsolute(baseUrl)
153+
? baseUrl
154+
: path.join(rootDir, baseUrl)
155+
} else {
156+
absoluteBase = rootDir
157+
}
153158

154159
const pathsObj: Record<string, string> = {}
155160
for (const [key, value] of Object.entries(paths)) {

0 commit comments

Comments
 (0)