Skip to content

Commit

Permalink
Fix build with TS alias without basePath (#11693)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
callingmedic911 authored and Josh-Walker-GM committed Nov 14, 2024
1 parent c608868 commit 1b6823f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changesets/11693.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Fix build with TS alias without basePath (#11693) by @callingmedic911

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`.
15 changes: 10 additions & 5 deletions packages/babel-config/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,21 @@ export const getPathsFromTypeScriptConfig = (
return {}
}

if (!config.compilerOptions?.baseUrl || !config.compilerOptions?.paths) {
if (!config.compilerOptions?.paths) {
return {}
}

const { baseUrl, paths } = config.compilerOptions

// Convert it to absolute path - on windows the baseUrl is already absolute
const absoluteBase = path.isAbsolute(baseUrl)
? baseUrl
: path.join(rootDir, baseUrl)
let absoluteBase: string
if (baseUrl) {
// Convert it to absolute path - on windows the baseUrl is already absolute
absoluteBase = path.isAbsolute(baseUrl)
? baseUrl
: path.join(rootDir, baseUrl)
} else {
absoluteBase = rootDir
}

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

0 comments on commit 1b6823f

Please sign in to comment.