cypress-axe
cypress-axe copied to clipboard
require is not defined on injectAxe - vite
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.