component-driven / component-driven/cypress-axe

require is not defined on injectAxe - vite

Open
#189 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
641
Forks
90
Avg merge
6h 8m
Merged PRs (30d)
1

Description

There is still an issue where it throws a required is not defined error.

"cypress-axe": "^1.6.0",
"axe-core": "^4.10.3"
"cypress": "14.5.3",
"vite": "^5.4.18",

When running cy.injectAxe(), I get:

index-C9bkuwCU.js:5316 ReferenceError: require is not defined
    at exports.injectAxe (http://localhost:4173/__cypress/tests?p=tests/e2e/support/index.js:74:190)
    at wrapped (http://localhost:4173/__cypress/runner/cypress_runner.js:141524:43)
    at <unknown> (http://localhost:4173/__cypress/runner/cypress_runner.js:147477:15)
    at tryCatcher (http://localhost:4173/__cypress/runner/cypress_runner.js:1777:23)
    at Promise._settlePromiseFromHandler (http://localhost:4173/__cypress/runner/cypress_runner.js:1489:31)
    at Promise._settlePromise (http://localhost:4173/__cypress/runner/cypress_runner.js:1546:18)
    at Promise._settlePromiseCtx (http://localhost:4173/__cypress/runner/cypress_runner.js:1583:10)
    at <unknown> (http://localhost:4173/__cypress/runner/cypress_runner.js:2352:20)
From previous event:
    at Promise.longStackTracesCaptureStackTrace [as _captureStackTrace] (http://localhost:4173/__cypress/runner/cypress_runner.js:3456:19)
    at Promise._then (http://localhost:4173/__cypress/runner/cypress_runner.js:1209:17)
    at Promise._passThrough (http://localhost:4173/__cypress/runner/cypress_runner.js:4080:17)
    at Promise.lastly.Promise.finally (http://localhost:4173/__cypress/runner/cypress_runner.js:4089:17)
    at Object.onRunnableRun (http://localhost:4173/__cypress/runner/cypress_runner.js:166940:53)
    at $Cypress.action (http://localhost:4173/__cypress/runner/cypress_runner.js:41560:28)
    at Runnable.run (http://localhost:4173/__cypress/runner/cypress_runner.js:148881:13)
    at Runner.runTest (http://localhost:4173/__cypress/runner/cypress_runner.js:159293:10)
    at <unknown> (http://localhost:4173/__cypress/runner/cypress_runner.js:159419:12)
    at next (http://localhost:4173/__cypress/runner/cypress_runner.js:159210:14)
    at <unknown> (http://localhost:4173/__cypress/runner/cypress_runner.js:159220:7)
    at next (http://localhost:4173/__cypress/runner/cypress_runner.js:159122:14)
    at <unknown> (http://localhost:4173/__cypress/runner/cypress_runner.js:159188:5)
    at timeslice (http://localhost:4173/__cypress/runner/cypress_runner.js:149232:27)

Which comes from this line on the injectAxe function:

var fileName = (injectOptions === null || injectOptions === void 0 ? void 0 : injectOptions.axeCorePath) || (typeof (commonjsRequire === null || commonjsRequire === void 0 ? void 0 : require.resolve) === "function" ? require.resolve("axe-core/axe.min.js") : "node_modules/axe-core/axe.min.js");

Any help would be appreciated.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the injectAxe function and the reported fileName expression, then reproduce cy.injectAxe() with the listed Cypress, Vite, cypress-axe, and axe-core versions. Trace how the bundled code handles require and require.resolve in the Vite browser context. Done means injectAxe runs without a require ReferenceError in this setup and the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cypress, typescript, vite
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.