cypress-io/cypress · error

Failed generating files: ${results.failed.map((e) => `${e}`)

Error message

Failed generating files: ${results.failed.map((e) => `${e}`)}

What it means

Thrown by CodegenActions.e2eExamples after running the code generator for e2e example specs. The codegen returns a results object with `.failed` and `.files`; if any file failed to generate (status other than add/overwrite/skip in the expected sense), Cypress aggregates the per-file error strings into one message and throws. Each entry in results.failed is itself an Error or error-like object stringified via template literal.

Source

Thrown at packages/data-context/src/actions/CodegenActions.ts:159

    const projectRoot = this.ctx.currentProject

    assert(projectRoot, `Cannot create e2e directory without currentProject.`)

    return path.join(projectRoot, 'cypress', 'e2e')
  }

  async e2eExamples (): Promise<NexusGenObjects['ScaffoldedFile'][]> {
    const projectRoot = this.ctx.currentProject

    assert(projectRoot, `Cannot create spec without currentProject.`)

    const results = await codeGenerator(
      { templateDir: templates['e2eExamples'], target: this.defaultE2EPath },
      {},
    )

    if (results.failed.length) {
      throw new Error(`Failed generating files: ${results.failed.map((e) => `${e}`)}`)
    }

    return results.files.map(({ status, file, content }) => {
      return {
        status: (status === 'add' || status === 'overwrite') ? 'valid' : 'skipped',
        file: { absolute: file, contents: content },
        description: 'Generated spec',
      }
    })
  }

  getWizardFrameworkFromConfig (): Cypress.ResolvedComponentFrameworkDefinition | undefined {
    const config = this.ctx.lifecycleManager.loadedConfigFile

    // If devServer is a function, they are using a custom dev server.
    if (!config?.component?.devServer || typeof config?.component?.devServer === 'function') {
      return undefined
    }

View on GitHub (pinned to 0d85fdc912)

Solutions

  1. Read the aggregated failed list in the error message — it tells you which file(s) and why.
  2. Ensure the target directory (defaultE2EPath) is writable and not locked by another process.
  3. Reinstall Cypress to restore the bundled templates (`npm install cypress`).
  4. If a conflict on an existing file is the cause, delete or move the existing file and retry.
Defensive patterns

Strategy: try-catch

Validate before calling

import { access, constants } from 'fs/promises'

async function isTargetWritable (dir: string): Promise<boolean> {
  try {
    await access(dir, constants.W_OK)
    return true
  } catch { return false }
}

Type guard

function codegenSucceeded (results: { failed: unknown[] }): boolean {
  return results.failed.length === 0
}

Try / catch

try {
  await ctx.actions.e2eExamples()
} catch (e) {
  if (/Failed generating files/.test(e.message)) {
    // Surface the per-file reasons from results.failed to the Launchpad UI
    showScaffoldFailure(e.message)
    return
  }
  throw e
}

Prevention

When it happens

Trigger: Clicking 'Scaffold examples' in the Launchpad / create-spec wizard for e2e when one of the template files cannot be written — destination directory not writable, template file missing from the bundled templates map, or a copy conflict the generator classifies as a hard failure rather than skip.

Common situations: Read-only project root, antivirus locking files on Windows, partial Cypress install missing the e2eExamples template bundle, or a destination path that already exists and the generator's overwrite policy treats it as failure.

Related errors


AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12). Data as JSON: /api/errors/34dc1cd1524a3652. Report an issue: GitHub.