Resolving Yarn2 + Cypress GitHub Action: Cannot find module ‘cypress’

Charles Stover
2 min readOct 23, 2021

An open issue exists for running the Cypress.io end-to-end test GitHub Action in a Yarn2 plug-and-play repository: the action fails with the following error:

Error: Cannot find module 'cypress'
Require stack:
- /home/runner/work/_actions/cypress-io/github-action/v2/dist/index.js

I dug into resolving this myself, and I found the root cause to be this line of the GitHub Action:

// If `command:` is provided, run it.
const customCommand = core.getInput('command')
if (customCommand) {
console.log('Using custom test command: %s', customCommand)
return execCommand(customCommand, true, 'run tests')
}
// If `command-prefix:` is provided, use it.
const commandPrefix = core.getInput('command-prefix')
if (commandPrefix) {
return runTestsUsingCommandLine()
}
// Otherwise, find `cypress` and run it.
debug('Running Cypress tests using NPM module API') debug(`requiring cypress dependency, cwd is ${process.cwd()}`)
debug(`working directory ${workingDirectory}`)
const cypressModulePath =
require.resolve('cypress', {
paths: [workingDirectory]
}) || 'cypress'
debug(`resolved cypress ${cypressModulePath}`)

In the above code, implementations that do not provide a command or command-prefix variable in the GitHub Action’s with configuration fallback to the require.resolve method in Node. This means that implementations that use command (like command: yarn cypress) or a…

--

--