diff --git a/packages/workspace/src/core/nx-deps/nx-deps-cache.spec.ts b/packages/workspace/src/core/nx-deps/nx-deps-cache.spec.ts index 07e5ade979..769501b153 100644 --- a/packages/workspace/src/core/nx-deps/nx-deps-cache.spec.ts +++ b/packages/workspace/src/core/nx-deps/nx-deps-cache.spec.ts @@ -1,9 +1,11 @@ import { NxJsonConfiguration, WorkspaceJsonConfiguration } from '@nrwl/devkit'; import { + createCache as _createCache, extractCachedFileData, ProjectGraphCache, shouldRecomputeWholeGraph, } from './nx-deps-cache'; +import { createCache } from './nx-deps-cache'; describe('nx deps utils', () => { describe('shouldRecomputeWholeGraph', () => { @@ -277,6 +279,17 @@ describe('nx deps utils', () => { }); }); + describe('createCache', () => { + it('should work with empty tsConfig', () => { + _createCache( + createNxJson({}), + createPackageJsonDeps({}), + createCache({}), + {} + ); + }); + }); + function createCache(p: Partial): ProjectGraphCache { const defaults: ProjectGraphCache = { version: '3.0', diff --git a/packages/workspace/src/core/nx-deps/nx-deps-cache.ts b/packages/workspace/src/core/nx-deps/nx-deps-cache.ts index d627dc8d77..89780edfc1 100644 --- a/packages/workspace/src/core/nx-deps/nx-deps-cache.ts +++ b/packages/workspace/src/core/nx-deps/nx-deps-cache.ts @@ -90,7 +90,7 @@ export function createCache( nxJson: NxJsonConfiguration<'*' | string[]>, packageJsonDeps: Record, projectGraph: ProjectGraph, - tsConfig: { compilerOptions: { paths?: { [p: string]: any } } } + tsConfig: { compilerOptions?: { paths?: { [p: string]: any } } } ) { const nxJsonPlugins = (nxJson.plugins || []).map((p) => ({ name: p, @@ -99,7 +99,8 @@ export function createCache( const newValue: ProjectGraphCache = { version: projectGraph.version || '5.0', deps: packageJsonDeps, - pathMappings: tsConfig.compilerOptions.paths || {}, + // compilerOptions may not exist, especially for repos converted through add-nx-to-monorepo + pathMappings: tsConfig.compilerOptions?.paths || {}, nxJsonPlugins, nodes: projectGraph.nodes, externalNodes: projectGraph.externalNodes,