{"record":{"id":"5a1f36d5e3667cad","repo":"cypress-io/cypress","slug":"tests-cannot-run-without-a-reference-to-cypress","errorCode":null,"errorMessage":"Tests cannot run without a reference to Cypress!","messagePattern":"Tests cannot run without a reference to Cypress!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"npm/webpack-dev-server/src/aut-runner.ts","lineNumber":8,"sourceCode":"/* eslint-env browser */\n\nexport function init (importPromises: Array<() => Promise<void>>, parent: Window = (window.opener || window.parent)) {\n  // @ts-expect-error\n  const Cypress = window.Cypress = parent.Cypress\n\n  if (!Cypress) {\n    throw new Error('Tests cannot run without a reference to Cypress!')\n  }\n\n  Cypress.onSpecWindow(window, importPromises)\n  Cypress.action('app:window:before:load', window)\n}\n","sourceCodeStart":1,"sourceCodeEnd":14,"githubUrl":"https://github.com/cypress-io/cypress/blob/0d85fdc91230885bca0a91df278312800a48b727/npm/webpack-dev-server/src/aut-runner.ts#L1-L14","documentation":"Thrown by the @cypress/webpack-dev-server browser-side aut-runner init when `parent.Cypress` is undefined. The runner copies window.Cypress from the opener/parent window; if that source window has no Cypress instance (the server did not inject the Cypress runtime), the AUT cannot wire commands and refuses to run. Cypress.action('app:window:before:load') and onSpecWindow never execute.","triggerScenarios":"init(importPromises, parent) runs in the AUT frame and `parent.Cypress` (or window.opener.Cypress) is null. Happens when the spec HTML is loaded outside the Cypress runner context — e.g. opened directly by file:// in a browser, served by a misconfigured dev server that stripped the Cypress injection, or when the parent frame navigated away before init ran.","commonSituations":"Opening the component runner HTML directly; a custom dev-server setup that bypasses Cypress's window:before:load hook that injects Cypress; an iframe timing race; running webpack-dev-server output outside Cypress.","solutions":["Do not open the spec/runner HTML directly — always drive CT through `cypress open --component` or `cypress run --component`.","If using a custom dev server, ensure Cypress's injection (via Cypress.action('app:window:before:load') / the CT webpack plugin) is not stripped.","Confirm the parent runner window is alive when init executes (avoid navigation away during load).","Reinstall/upgrade @cypress/webpack-dev-server to match your Cypress version so the injection contract holds."],"exampleFix":"// before: opening the served HTML directly\ncurl http://localhost:5173/__cypress/runner  // -> throws in browser console\n// after: run through Cypress\ncypress run --component --spec src/App.cy.tsx","handlingStrategy":"validation","validationCode":"// browser-side guard\nconst parent = window.opener || window.parent\nif (!(parent && (parent as any).Cypress)) {\n  throw new Error('Opened outside Cypress runner; launch via cypress run/open')\n}","typeGuard":"const hasParentCypress = (w: Window): boolean => !!(w && (w as any).Cypress)","tryCatchPattern":null,"preventionTips":["Always launch CT via cypress open/run, not by opening the runner HTML directly.","Preserve Cypress's window:before:load injection in any custom dev server.","Keep @cypress/webpack-dev-server version aligned with your Cypress version."],"tags":["webpack","dev-server","browser","runtime","cypress-instance"],"backgroundTag":null,"analyzedSha":"0d85fdc91230885bca0a91df278312800a48b727","analyzedAt":"2026-08-12T16:24:28.056Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}