Skip to content

fix(js): use TypeScript readConfigFile instead of JSON.parse in resolvePathsBaseUrl#35539

Open
aqeelat wants to merge 1 commit intonrwl:masterfrom
aqeelat:fix/35537-resolve-paths-jsonc
Open

fix(js): use TypeScript readConfigFile instead of JSON.parse in resolvePathsBaseUrl#35539
aqeelat wants to merge 1 commit intonrwl:masterfrom
aqeelat:fix/35537-resolve-paths-jsonc

Conversation

@aqeelat
Copy link
Copy Markdown

@aqeelat aqeelat commented May 1, 2026

Current Behavior

resolvePathsBaseUrl in packages/js/src/utils/typescript/ts-config.ts walks the tsconfig extends chain using JSON.parse(readFileSync(...)) to find where paths is defined. JSON.parse cannot handle // or /* */ comments (JSONC), which are extremely common in tsconfig files. When parsing fails, the catch block silently skips the file, breaking the extends chain walk. The function never reaches tsconfig.base.json (where paths and baseUrl are defined), so it falls back to the project's own directory as the resolution base, producing incorrect path mappings like {workspaceRoot}/libs/my-lib/dist/libs/data-layer instead of {workspaceRoot}/dist/libs/data-layer.

This is a regression introduced in v22.7.0 by PR #34965.

Expected Behavior

Buildable library builds should resolve workspace dependencies correctly, even when tsconfig files in the extends chain contain JSONC comments (// or /* */). The fix uses TypeScript's readConfigFile (which handles JSONC) — the same approach already used by readTsConfig in the same file.

Related Issue(s)

Fixes #35537

…vePathsBaseUrl

resolvePathsBaseUrl walked the tsconfig extends chain using JSON.parse,
which cannot handle // or /* */ comments (JSONC). When a tsconfig in the
chain contained comments, parsing failed silently and broke the extends
walk, causing workspace path mappings to resolve relative to the project
directory instead of the workspace root.

Use ts.readConfigFile (which handles JSONC) — the same approach already
used by readTsConfig in the same file.

Fixes nrwl#35537
@aqeelat aqeelat requested a review from a team as a code owner May 1, 2026 20:53
@aqeelat aqeelat requested a review from FrozenPandaz May 1, 2026 20:53
@netlify
Copy link
Copy Markdown

netlify Bot commented May 1, 2026

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 991a19b

@netlify
Copy link
Copy Markdown

netlify Bot commented May 1, 2026

👷 Deploy request for nx-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 991a19b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression (22.7.0): resolvePathsBaseUrl uses JSON.parse — breaks on tsconfig files with // comments (JSONC)

1 participant