cypress-io/cypress · error
Cannot generate a spec without a framework
Error message
Cannot generate a spec without a framework
What it means
Thrown by SpecOptions.getComponentCodeGenOptions when this.options.framework is falsy. Component spec generation needs a framework (React, Vue, etc.) to pick the right template and import shape; e2e generation does not. The code path is reached only when codeGenType === 'component', and the guard is a hard stop because there is no sensible default framework.
Source
Thrown at packages/data-context/src/codegen/spec-options.ts:55
this.parsedPath = path.parse(options.codeGenPath)
}
async getCodeGenOptions () {
if (this.options.codeGenType === 'component') {
return this.getComponentCodeGenOptions()
}
return {
codeGenType: this.options.codeGenType,
fileName: await this.buildFileName(),
templateKey: this.options.codeGenType as TemplateKey,
overrideCodeGenDir: '',
}
}
private async getComponentCodeGenOptions () {
if (!this.options.framework) {
throw new Error('Cannot generate a spec without a framework')
}
switch (this.options.framework.codeGenFramework) {
case 'react':
return await this.getReactSpecOptions()
case 'vue':
return await this.getVueSpecOptions()
default:
throw new Error(`Unable to generate spec for ${this.options.framework.codeGenFramework}`)
}
}
private getRelativePathToComponent (specParsedPath?: ParsedPath) {
if (specParsedPath) {
const componentPathRelative = path.relative(specParsedPath.dir, this.parsedPath.dir)
const componentPath = path.join(componentPathRelative, this.parsedPath.base)
View on GitHub (pinned to 0d85fdc912)
Solutions
- In the Launchpad, complete the framework setup step so Cypress records a detected/selected framework before generating a component spec.
- Install at least one component-testing-supported framework (react, vue, etc.) and import it in a source file so detection succeeds.
- If detection should work, restart the Launchpad so the framework cache refreshes.
- For unsupported frameworks, fall back to generating an empty component spec (componentEmpty template) or use e2e generation.
Defensive patterns
Strategy: validation
Validate before calling
function assertFrameworkForComponentSpec (opts: { codeGenType: string; framework?: unknown }) {
if (opts.codeGenType === 'component' && !opts.framework) {
throw new Error('Configure a component framework in the Launchpad before generating a spec')
}
} Type guard
function hasFramework (opts: { framework?: unknown }): opts is { framework: Cypress.ResolvedComponentFrameworkDefinition } {
return Boolean(opts.framework)
} Prevention
- Complete framework setup in the Launchpad before scaffolding component specs.
- Install at least one supported component framework and import it in a source file.
- Restart the Launchpad to refresh framework detection.
When it happens
Trigger: The Launchpad / scaffold flow calls SpecOptions with codeGenType: 'component' but no framework detected in the project. This happens when framework detection (@packages/scaffold-config) returned nothing — e.g. a project with no React/Vue/Angular/Svelte imports, a brand-new empty project, or a project using a framework Cypress does not yet detect.
Common situations: User clicked 'Create new spec' -> 'Component' before configuring a component framework in the Launchpad, framework detection ran on a project whose source files do not import a known framework, or the framework detection cache is stale.
Related errors
- Unable to generate spec for ${this.options.framework.codeGen
- Failed generating files: ${results.failed.map((e) => `${e}`)
- cy.visit from a component spec is not allowed
- cy.session from a component spec is not allowed
- cy.origin from a component spec is not allowed
AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12).
Data as JSON: /api/errors/5a41490f56076908.
Report an issue: GitHub.