Search code examples
reactjstypescriptvisual-studio-codenpmcypress

ReactJS VSCode: Cannot find name 'cy' in Cypress integration testing


I have a ReactJS Typescript project with NPM and VSCode.

I am getting the following syntax error in VSCode, even though all my Cypress tests run correctly.

Error: Cannot find name 'cy' 

How can I fix?

enter image description here

I tried the following solution and still receiving syntax errors,

npm install eslint-plugin-cypress --save-dev

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

Update Answer:

Found Official solution from Cypress Documentation, posted in my answer below https://stackoverflow.com/a/77476529/15435022


Solution

  • Official Cypress Documentation:

    https://docs.cypress.io/guides/tooling/typescript-support

    For Typescript configuration, Add this to tsconfig.json inside your cypress root folder:

    {
      "compilerOptions": {
        "target": "es5",
        "lib": ["es5", "dom"],
        "types": ["cypress", "node"]
      },
      "include": ["**/*.ts"]
    }