ESLint: 'cy' is not defined (Cypress) ESLint: 'cy' is not defined (Cypress) reactjs reactjs

ESLint: 'cy' is not defined (Cypress)


I got that error after upgrading to cypress version 4+. I installed the eslint-plugin-cypresshttps://github.com/cypress-io/eslint-plugin-cypressand activated it in the extends configuration either in package.json or in separate config file:

"eslintConfig": {  "extends": [    "plugin:cypress/recommended"  ]},


Add .eslintrc.json to cypress directory

In .eslintrc.json

{  "extends": [    "plugin:cypress/recommended"  ]}

enter image description here

  • I do not install eslint-plugin-cypress, and it fix the problem


Specify cy in eslintrc globals

Answered here

cy is a global variable. Much like location. So really it is window.cy. You can add it to the globals in Eslint. Don't import cy from cypress.

{  "globals": {    "cy": true  }}

Added that to my .eslintrc and fixed the issue