cypress: Cypress Crash: Uncaught TypeError: Cannot read properties of undefined (reading 'emit')

Current behavior

Upon finishing running my Cypress script, Cypress would crash (On Chrome Latest)

In dev tools we can see the following error:

cypress_runner.js:191727 Uncaught TypeError: Cannot read properties of undefined (reading 'emit')
    at Socket.<anonymous> (cypress_runner.js:191727)
    at Socket.../../node_modules/component-emitter/index.js.Emitter.emit (cypress_runner.js:18455)
    at Socket.emit (cypress_runner.js:199652)
    at Socket.emitEvent (cypress_runner.js:199401)
    at Socket.onevent (cypress_runner.js:199388)
    at Socket.onpacket (cypress_runner.js:199352)
    at Manager.../../node_modules/component-emitter/index.js.Emitter.emit (cypress_runner.js:18455)
    at Manager.emitReserved (cypress_runner.js:199665)
    at Manager.ondecoded (cypress_runner.js:198944)
    at Decoder.../../node_modules/component-emitter/index.js.Emitter.emit (cypress_runner.js:18455)
    at Decoder.add (cypress_runner.js:199978)
    at Manager.ondata (cypress_runner.js:198936)
    at Socket.../../node_modules/component-emitter/index.js.Emitter.emit (cypress_runner.js:18455)
    at Socket.onPacket (cypress_runner.js:196867)
    at WS.<anonymous> (cypress_runner.js:196676)
    at WS.../../node_modules/component-emitter/index.js.Emitter.emit (cypress_runner.js:18455)

Clicking on the .js line:
 lodash__WEBPACK_IMPORTED_MODULE_0___default.a.each(socketToDriverEvents, event => {
      ws.on(event, (...args) => {
        Cypress.emit(event, ...args);
      });
    });

Desired behavior

No response

Test code to reproduce

Issue seems to happen on screen redirection, not sure if its due to when a session becomes invalid. If anyone can explain what the above is related to I can investigate more before providing sample code.

Cypress Version

9.1.1

Other

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 26
  • Comments: 38 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I can confirm this issue existed. On my side, this is all about Cypress Component Testing.

And I think I found some clues of the bug. This bug will only happen if you install any Cypress version large than v.8.1.0 (i.e. v.8.1.0 is safe)

The issue is reproducible, and it’s easy to do:

  1. Clone: https://github.com/cypress-io/cypress-component-testing-examples/tree/main/create-nuxt-app
  2. update Cypress package to 8.2.0
  3. run npx cypress open-ct
  4. you can see the browser console show the error(see attachment)
  5. but if you update Cypress to 8.1.0, no error anymore!!!

image

cc @bahmutov

Thx for reading. And hope this bug can be fixed.

Issue still exists in Cypress 10.4.0 - not sure if there is more then one problem being discussed here but its still a showstopper for myself. This only issue with Cypress I see when Cypress crash and no proper way to debug. Surely this bug should have more priority then backlogged.

Issues still exists in Cypress 9.6, Im hoping fix comes in Cypress 10, how can we get a Cypress dev on this?

I got the same issue with vue 3. Tried it with the hello-world example project and followed your tutorial: https://www.cypress.io/blog/2021/04/06/getting-start-with-cypress-component-testing-vue-2-3/

package.json: ... "dependencies": { "core-js": "^3.20.2", "vue": "^3.2.26", "webpack": "^5.65.0" }, "devDependencies": { "@cypress/vue": "^3.1.0", "@cypress/webpack-dev-server": "^1.8.0", "@vue/cli-plugin-babel": "^5.0.0-rc.1", "@vue/cli-plugin-eslint": "^5.0.0-rc.1", "@vue/cli-service": "^5.0.0-rc.1", "@vue/compiler-sfc": "^3.2.26", "autoprefixer": "^10.4.1", "babel-eslint": "^11.0.0-beta.2", "cypress": "^9.2.1", "eslint": "^8.6.0", "eslint-plugin-cypress": "^2.12.1", "eslint-plugin-vue": "^8.2.0" }, "eslintConfig": { "root": true, "env": { "node": true }, "extends": [ "plugin:vue/vue3-essential", "eslint:recommended", "plugin:cypress/recommended" ], "parserOptions": { "parser": "babel-eslint" }, "rules": {} }, ...

cypress/plugins/index.js: const { startDevServer } = require('@cypress/webpack-dev-server') const webpackConfig = require('@vue/cli-service/webpack.config') module.exports = (on, config) => { on('dev-server:start', (options) => { return startDevServer({ options, webpackConfig, }) }) return config }

cypress.json: { "component": { "componentFolder": "src", "testFiles": "**/*.spec.js" } }

  1. run npx cypress open-ct
  2. selectHelloWorld.spec.js

=> UI stuck on “Your tests are loading…”

Console output: cypress_runner.js:209081 Uncaught TypeError: Cannot read properties of undefined (reading 'emit') at Socket.<anonymous> (cypress_runner.js:209081:17) at Socket.../../node_modules/component-emitter/index.js.Emitter.emit (cypress_runner.js:31735:20) at Socket.emit (cypress_runner.js:217050:15) at Socket.emitEvent (cypress_runner.js:216799:20) at Socket.onevent (cypress_runner.js:216786:18) at Socket.onpacket (cypress_runner.js:216750:22) at Manager.../../node_modules/component-emitter/index.js.Emitter.emit (cypress_runner.js:31735:20) at Manager.emitReserved (cypress_runner.js:217063:15) at Manager.ondecoded (cypress_runner.js:216342:14) at Decoder.../../node_modules/component-emitter/index.js.Emitter.emit (cypress_runner.js:31735:20) at Decoder.add (cypress_runner.js:217376:23) at Manager.ondata (cypress_runner.js:216334:22) at Socket.../../node_modules/component-emitter/index.js.Emitter.emit (cypress_runner.js:31735:20) at Socket.onPacket (cypress_runner.js:214265:16) at WS.<anonymous> (cypress_runner.js:214074:14) at WS.../../node_modules/component-emitter/index.js.Emitter.emit (cypress_runner.js:31735:20)

I’m pretty new to cypress, so perhaps I am missing something? Help / Suggestions are very appreciated !

npm: 8.3.0 node: 17.3.0

Edit:

I downgraded node to 16.13.2, now I still got the error in the console but the test works. My bad 😕

Issue still existis in Cypress 12.3.0, I think its todo with perhaps switching from iframe to non iframe solution. Waiting for iFrame support from Cypress for very long time.