Skip to content

Commit

Permalink
fix(js): handle tsconfig file with no compilerOptions (#25966)
Browse files Browse the repository at this point in the history
Handles adding a root `tsconfig.base.json` when there is a root
`tsconfig.json` with no `compilerOptions` property.

Prerequisites:
Have a repository has a root `tsconfig.json` with no `compilerOptions`
property and there is no root `tsconfig.base.json`.

Steps to reproduce:
1. Generate a js library (`nx g @nx/js:lib my-lib`)

Expected results:
Library is created.

Actual results:
There is an error.

```
 NX   Cannot read properties of undefined (reading 'rootDir')
```

This PR fixes the error.
  • Loading branch information
isaacplmann authored May 23, 2024
1 parent 94707d9 commit a1ba0ad
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/js/src/utils/typescript/create-ts-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ export function extractTsConfigBase(host: Tree) {
const tsconfig = readJson(host, 'tsconfig.json');
const baseCompilerOptions = {} as any;

for (let compilerOption of Object.keys(tsConfigBaseOptions)) {
baseCompilerOptions[compilerOption] =
tsconfig.compilerOptions[compilerOption];
delete tsconfig.compilerOptions[compilerOption];
if (tsconfig.compilerOptions) {
for (let compilerOption of Object.keys(tsConfigBaseOptions)) {
baseCompilerOptions[compilerOption] =
tsconfig.compilerOptions[compilerOption];
delete tsconfig.compilerOptions[compilerOption];
}
}
writeJson(host, 'tsconfig.base.json', {
compileOnSave: false,
Expand Down

0 comments on commit a1ba0ad

Please sign in to comment.