I'm running Cypress for my Angular project and suddenly the last few days cypress started throwing the following error both locally and in my CI environment.
1) An uncaught error was detected outside of a test:
Uncaught Error: Your OS "browser" is currently not supported by node-cachedir.
This error originated from your test code, not from Cypress.
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.
Not to explode, or at least give me more feedback as to what is actually wrong :'(
Here is my app repo: https://github.com/bradtaniguchi/ng-flare/tree/93aad47d0b5fe446638802c38320890c726dec13
If you wanted to run the project just run npm install and then npm run e2e to start cypress.
cypress config: https://github.com/bradtaniguchi/ng-flare/blob/93aad47d0b5fe446638802c38320890c726dec13/projects/main-client-e2e/cypress.json
(I also tried 3.3.1)
Distributor ID: Debian
Description: Debian GNU/Linux 9.9 (stretch)
Release: 9.9
Codename: stretch
Let me know if I should provide any logs, or extra information. I couldn't find any docs/info on the error so I'll be happy to provide more info, any info to help debug this issue. :)
I did a little digging on my side and found this issue:
os.platform() returns 'browser', which isn't an OS which states the issue was related to browserify and nothing more.
I also noticed the issue only appears with the "electron browser", Chrome doesn't connect (this could be 100% unrelated)
I also added some console.log to help debug the issue at this line:
https://github.com/cypress-io/cypress/blob/develop/cli/lib/util.js#L286
// from this
getCacheDir () {
return cachedir('Cypress')
}
// to this:
getCacheDir () {
const val = cachedir('Cypress');
console.log('get cacheDir', val);
return val;
}
This is then printed:
get cacheDir /home/bradtaniguchi/.cache/Cypress linux
which prints out twice after Angular compiles, and before cypress prints (Run Starting).
Finally here is the full stack (right after the Angular build), as I realized I didn't provide it the first time.
====================================================================================================
(Run Starting)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Cypress: 3.1.0 โ
โ Browser: Electron 59 โ
โ Specs: 1 found (login.spec.js) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Running: login.spec.js... (1 of 1)
Warning: Cypress can only record videos when running headlessly.
You have set the 'electron' browser to run headed.
A video will not be recorded when using this mode.
1) An uncaught error was detected outside of a test
0 passing (686ms)
1 failing
1) An uncaught error was detected outside of a test:
Uncaught Error: Your OS "browser" is currently not supported by node-cachedir.
This error originated from your test code, not from Cypress.
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.
at http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:37092:13
at Object.<anonymous> (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:37094:2)
at Object.230._process (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:37110:4)
at o (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:1:265)
at http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:1:316
at Object.<anonymous> (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:44371:16)
at Object.367../logger (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:44583:4)
at o (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:1:265)
at http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:1:316
at Object.<anonymous> (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:42599:12)
at Object.353../lib/cypress (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:42622:4)
at o (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:1:265)
at http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:1:316
at Object.193.../e2e-config.env (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:33164:1)
at o (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:1:265)
at r (http://localhost:4200/__cypress/tests?p=../../dist/out-tsc/apps/main-client-e2e/src/integration/login.spec.js-733:1:431)
(Results)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Tests: 1 โ
โ Passing: 0 โ
โ Failing: 1 โ
โ Pending: 0 โ
โ Skipped: 0 โ
โ Screenshots: 1 โ
โ Video: false โ
โ Duration: 0 seconds โ
โ Spec Ran: login.spec.js โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
(Screenshots)
- /home/bradtaniguchi/Projects/ng-flare/dist/out-tsc/apps/main-client-e2e/screenshots/login.spec.js/An uncaught error was detected outside of a test (failed).png (2176x1182)
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ login.spec.js 622ms 1 - 1 - - โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 of 1 failed (100%) 622ms 1 - 1 - -
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] e2e: `ng e2e "--project=main-client-e2e-cypress"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/bradtaniguchi/.npm/_logs/2019-06-30T08_26_21_184Z-debug.log
This error is happening due to the import 'cypress'; at the top of the login.spec file. If I remove this, the test continues normally. Any reason you are importing this there?
Run the following with cypress open or cypress run
import 'cypress'

I added import 'cypress' to help fix errors I was getting from VSCode saying cy is not known or cypress types affecting my normal karma/jasmine .spec files. I assume in my haste of trying different things to fix the linting issues I left the import there and totally forgot about it and never thought about the repercussions of it!
**So yes just removing import 'cypress' did the trick!!!
๐
Check out our TypeScript doc for some linting help https://on.cypress.io/typescript-support
You can also add /// <reference types="cypress" /> to the top of your file.
We had the same issue on our team. It was an imported lib that caused the issue. Lib was useless so our fix was just removing this new import. Hope this will help future QAs.
Most helpful comment
This error is happening due to the
import 'cypress';at the top of thelogin.specfile. If I remove this, the test continues normally. Any reason you are importing this there?To recreate:
Run the following with
cypress openorcypress run