13

When trying to npm install -D cypress-xpath into a Cypress project [require('cypress-xpath') added to my cypress/support/index.js] with the cypress-cucumber-preprocessor already installed I am getting the below Error in the plugins > index.js file for "/// <reference types="cypress" />"?

Cannot find type definition file for 'cypress'.ts(2688)

Added to plugins > index.js file

const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
on('file:preprocessor', cucumber())
}

package.json file

"devdependencies": {
    "cypress": "^8.3.1",
    "cypress-cucumber-preprocessor": "^4.2.0"
  },
  "Dependencies": {
    "cypress-xpath": "^1.6.2"
  }

support > index.js file

require('cypress-xpath')

When running:

npx cypress open

The plugins file is missing or invalid.

Your pluginsFile is set to C:\Users\Delwin\VSCode\Cypress\Cucumber1\cypress\plugins\index.js, but either the file is missing, it contains a syntax error, or threw an error when required. The pluginsFile must be a .js, .ts, or .coffee file.

Or you might have renamed the extension of your pluginsFile. If that's the case, restart the test runner.

Please fix this, or set pluginsFile to false if a plugins file is not necessary for your project.

Error: Cannot find module 'cypress-cucumber-preprocessor'

Delwin Horsthemke
  • 131
  • 1
  • 1
  • 3
  • I met the same error described in your title(TS2688), and I solve it by upgrade my cypress version. Here's the [detail](https://ezdocs.notion.site/Cypress-10-1-0-ts-TS2688-c4a7b6a432664c1e835c9ca6dc39106f). – HKK Oct 15 '22 at 15:46

4 Answers4

7

My problem was solved by installing latest cypress types

npm i -D @types/cypress@latest

Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73
0

I had same error and I fixed by installing cypress, https://docs.cypress.io/guides/getting-started/installing-cypress

Neck
  • 91
  • 1
  • 3
0

Add <reference types="@cypress/xpath into the command.js fileenter image description here

visakh.j.b
  • 61
  • 3
0

I tried everything, but installing cypress in the project root path and creating "jsconfig.json" in the project root folder, solved the problem.

jsconfig.json ->

{
    "include": ["./node_modules/cypress", "cypress/**/*.js"]
  }
Vidhya
  • 79
  • 2
  • 6