From a1ba0ad7006522a4d2cb27db7610c37502912f0a Mon Sep 17 00:00:00 2001 From: Isaac Mann Date: Thu, 23 May 2024 15:43:35 -0400 Subject: [PATCH] fix(js): handle tsconfig file with no compilerOptions (#25966) 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. --- packages/js/src/utils/typescript/create-ts-config.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/js/src/utils/typescript/create-ts-config.ts b/packages/js/src/utils/typescript/create-ts-config.ts index e862b2c95e3c9..4bbd3253e9d96 100644 --- a/packages/js/src/utils/typescript/create-ts-config.ts +++ b/packages/js/src/utils/typescript/create-ts-config.ts @@ -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,