question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to start Cypress with ELECTRON_RUN_AS_NODE=1

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
lmiller1990commented, Sep 1, 2022

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?

0reactions
lmiller1990commented, Dec 20, 2022

It says missing dependency, but this might be a red herring.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress failed to start on Windows - Stack Overflow
→ Cypress Version: 1.4.1 Cypress failed to start. This is usually caused by a missing library or dependency. The error below should indicate...
Read more >
Troubleshooting | Cypress Documentation
If the smoke test fails to execute, check if a shared library is missing (a common problem on Linux machines without all of...
Read more >
cypress - npm
Cypress comes packaged as an npm module, which is all you need to get started testing. After installing you'll be able to: Open...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found