cypress-io/cypress · error · Error
Could not compile application files
Error message
Could not compile application files
What it means
Raised by startDevServer() in the @cypress/schematic Angular builder when the scheduled dev-server target returns output.success === false in non-watch mode. The builder delegates app compilation to the Angular dev-server target (referenced by devServerTarget, e.g. project:serve); when that build fails, Cypress has no baseUrl to test against, so the builder aborts with this generic message rather than running tests against a broken app.
Source
Thrown at npm/cypress-schematic/src/builders/cypress/index.ts:127
switchMap((builderName) => {
let overrides = {}
// @NOTE: Do not forward watch option if not supported by the target dev server,
// this is relevant for running Cypress against dev server target that does not support this option,
// for instance @nguniversal/builders:ssr-dev-server.
// see https://github.com/nrwl/nx/blob/f930117ed6ab13dccc40725c7e9551be081cc83d/packages/cypress/src/executors/cypress/cypress.impl.ts
if (builderName !== '@nguniversal/builders:ssr-dev-server') {
// eslint-disable-next-line no-console
console.info(`Passing watch mode to DevServer - watch mode is ${watch}`)
overrides = {
watch,
}
}
return scheduleTargetAndForget(context, targetFromTargetString(devServerTarget), overrides).pipe(
map((output: any) => {
if (!output.success && !watch) {
throw new Error('Could not compile application files')
}
return output.baseUrl as string
}),
)
}),
)
}
export default createBuilder<CypressBuilderOptions>(runCypress)
View on GitHub (pinned to 0d85fdc912)
Solutions
- Read the builder output ABOVE this error — the real Angular compiler errors are logged there. Fix the reported TS/template errors first.
- Run the dev server target directly (e.g. `ng serve` or `ng run <project>:serve`) in isolation to reproduce and fix compile failures.
- Confirm devServerTarget in angular.json points at an existing serve target for the right project.
- Match Angular CLI / devkit versions across the workspace; reinstall dependencies.
Example fix
// before: devServerTarget points at a serve target that fails to compile // after: // 1. run `ng run app:serve` and fix TS/template errors // 2. then re-run `ng run app:cypress`
Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the devServerTarget builds before wiring it to the Cypress builder: // run `ng run <project>:serve` (or the configured target) and exit non-zero on failure // before scheduling cypress.
Try / catch
// In a wrapper script around `ng run app:cypress`:
try {
await exec('ng run app:cypress')
} catch (e) {
if (/Could not compile application files/.test(String(e))) {
// the real compiler errors are above; re-run `ng run app:serve` to surface them
await exec('ng run app:serve')
}
throw e
} Prevention
- Keep the Angular app compiling green with `ng build` before adding Cypress to the pipeline.
- Pin Angular CLI/devkit versions across the workspace.
- Read the full builder log — the real diagnostics are printed above this generic message.
When it happens
Trigger: Running `ng run <project>:cypress` (or cypress-run) where the devServerTarget's serve build emits TypeScript/Angular compile errors and watch is false (single run). The thrown error masks the underlying Angular compiler diagnostics, which are printed above it in the builder log.
Common situations: A TypeScript or template compile error in the Angular app; a missing or misnamed devServerTarget in angular.json; Angular CLI version mismatch; an AOT production build failure only triggered in CI; the dev server target name changed after a refactor.
Related errors
- Could not find a project with projectType "application" in "
- Could not resolve "${dep}". Do you have "@angular-devkit/bui
- Could not find angular.json. Looked in ${projectRoot} and up
- projects in angular.json is not defined
- angular.json not found
AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12).
Data as JSON: /api/errors/d0cb273b2e6ff454.
Report an issue: GitHub.