cypress: Unable to start Cypress with ELECTRON_RUN_AS_NODE=1

Current behavior

If you set env with ELECTRON_RUN_AS_NODE=1, with MacOS, you are not able to start the Cypress with

ELECTRON_RUN_AS_NODE=1 npx cypress run

You’ll get error: Error: Cannot find module '/Users/<username>/Library/Caches/Cypress/10.6.0/Cypress.app/Contents/MacOS/Contents/Resources/app/index.js'

Checking the code, it seems that here is where it went wrong: https://github.com/cypress-io/cypress/blob/b615e8ac30b681b4dc8485afe9814ff453da1fbf/cli/lib/exec/spawn.js#L175

The correct path, at least for Mac, should be:

path.join(state.getBinaryPkgPath(path.join(executable, '..', '..', '..')), '..', 'index.js');

Desired behavior

Cypress should start correctly

Test code to reproduce

Try run with

ELECTRON_RUN_AS_NODE=1 npx cypress run

Cypress Version

10.6.0

Node version

16.0

Operating System

macOS

Debug Logs

No response

Other

Cypress 10.7.0 (latest) also has this problem

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 2
  • Comments: 20 (12 by maintainers)

Most upvoted comments

I can get around the issue mentioned by @lsantos10 ^^ if I run npx cypress verify in CI first without ELECTRON_RUN_AS_NODE: 1, however it still doesn’t work.

After running npx cypress verify first, I then see a different error message on Ubuntu 22.04 / Cypress 12.13.0 / Node.js 18.16.0

“Error: Cannot find module ‘./start-cypress’”

Edit: Still reproducible on Cypress 13.4.0 with Node.js 18.18.2.

See repo https://github.com/MikeMcC399/cy-xvfb-test

Workflow chrome_as_node.yml

Run npx cypress run --browser chrome
  npx cypress run --browser chrome
  shell: /usr/bin/bash -e {0}
  env:
    ELECTRON_RUN_AS_NODE: 1
Error: Cannot find module './start-cypress'
Require stack:
- /home/runner/.cache/Cypress/12.13.0/Cypress/resources/app/packages/server/index.jsc
    at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
    at Module._load (node:internal/modules/cjs/loader:785:27)
    at c._load (node:electron/js2c/asar_bundle:5:13339)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at i (/home/runner/.cache/Cypress/12.13.0/Cypress/resources/app/index.js:1:2232)
    at startCypress (evalmachine.<anonymous>:1:770705)
    at evalmachine.<anonymous>:1:770965
    at v (/home/runner/.cache/Cypress/12.13.0/Cypress/resources/app/index.js:1:2573)
    at Object.<anonymous> (/home/runner/.cache/Cypress/12.13.0/Cypress/resources/app/index.js:1:2764)
    at Module._compile (node:internal/modules/cjs/loader:1120:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/runner/.cache/Cypress/12.13.0/Cypress/resources/app/packages/server/index.jsc'
  ]
}
Error: Process completed with exit code 1.

I got the same problem on MacOS. It’s different on Linux:

$ ELECTRON_RUN_AS_NODE=1 yarn cypress run                                                                         main
yarn run v1.22.11
warning package.json: No license field
$ /home/lachlan/code/dump2/rhythm/node_modules/.bin/cypress run
Cannot find module 'electron'
Require stack:
- /home/lachlan/.cache/Cypress/10.7.0/Cypress/resources/app/packages/server/lib/makeDataContext.js
- /home/lachlan/.cache/Cypress/10.7.0/Cypress/resources/app/packages/server/lib/modes/index.js
- /home/lachlan/.cache/Cypress/10.7.0/Cypress/resources/app/packages/server/lib/cypress.js
- /home/lachlan/.cache/Cypress/10.7.0/Cypress/resources/app/packages/server/index.js
- /home/lachlan/.cache/Cypress/10.7.0/Cypress/resources/app/index.js
Error: Cannot find module 'electron'
Require stack:

Seems similar to #17412.

Looking at the docs

Using the ELECTRON_RUN_AS_NODE=1 env var is experimental and not fully tested, so may not work in all environments.

To figure out the priority on fixing this bug - do you have a specific use case in mind where you need to launch with ELECTRON_RUN_AS_NODE?