diff --git a/packages/cypress/src/generators/configuration/configuration.ts b/packages/cypress/src/generators/configuration/configuration.ts index 4e864a9d183bb..2410353e0e6e7 100644 --- a/packages/cypress/src/generators/configuration/configuration.ts +++ b/packages/cypress/src/generators/configuration/configuration.ts @@ -122,7 +122,8 @@ function ensureDependencies(tree: Tree, options: NormalizedSchema) { } function normalizeOptions(tree: Tree, options: CypressE2EConfigSchema) { - const projectConfig = readProjectConfiguration(tree, options.project); + const projectConfig: ProjectConfiguration | undefined = + readProjectConfiguration(tree, options.project); if (projectConfig?.targets?.e2e) { throw new Error(`Project ${options.project} already has an e2e target. Rename or remove the existing e2e target.`); @@ -131,7 +132,7 @@ Rename or remove the existing e2e target.`); if ( !options.baseUrl && !options.devServerTarget && - !projectConfig.targets.serve + !projectConfig?.targets?.serve ) { throw new Error(`The project ${options.project} does not have a 'serve' target. In this case you need to provide a devServerTarget,':[:]', or a baseUrl option`); @@ -141,7 +142,7 @@ In this case you need to provide a devServerTarget,':[: const devServerTarget = options.devServerTarget ?? - (projectConfig.targets.serve ? `${options.project}:serve` : undefined); + (projectConfig?.targets?.serve ? `${options.project}:serve` : undefined); if (!options.baseUrl && !devServerTarget) { throw new Error('Either baseUrl or devServerTarget must be provided');