Getting the error "Cannot find module './commands'" while trying to run cypress tests

1.8k views Asked by At

When I'm trying to run cypress test I'm getting this error:

The following error originated from your test code, not from Cypress.

\> Cannot find module './commands'

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.

I was expecting my tests to run, and I've tried to create an index.js in the support folder with:

import './commands'

Cypress.on('uncaught:exception', (err, runnable) => {
  return false;
})

But that doesn't seem to work.

1

There are 1 answers

0
Ali Suliman On

When I had this issue it was because I tried to import from the wrong file.

Instead of importing in the test file, commands should be imported into /cypress/support/e2e(.js|.ts) file.

Ref Custom Commands

We recommend defining queries is in your cypress/support/commands.js file, since it is loaded before any test files are evaluated via an import statement in the supportFile.

That way they are available in any test that requires them. This is because the /cypress/support/e2e.js file is automatically integrated into the start of any and all test runs.