Cannot find type definition file for 'cypress'.ts

Viewed 5925

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'

2 Answers

My problem was solved by installing latest cypress types

npm i -D @types/cypress@latest

Related