Delwin Horsthemke
Delwin Horsthemke

Reputation: 181

Cannot find type definition file for 'cypress'.ts

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'

Upvotes: 18

Views: 24027

Answers (6)

Jayashani Mandila
Jayashani Mandila

Reputation: 11

I added the following tsconfig.json file an ran npm i -D @types/cypress@latest worked for me.

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

Upvotes: 1

Alekhya Uppari
Alekhya Uppari

Reputation: 1

My problem got sloved by writing

reference types="@cypress/xpath"

instead of

reference types="cypress-xpath"

Upvotes: 0

ViAi
ViAi

Reputation: 308

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"]
  }

Upvotes: 0

visakh.j.b
visakh.j.b

Reputation: 71

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

Upvotes: 0

Akshay Vijay Jain
Akshay Vijay Jain

Reputation: 15945

My problem was solved by installing latest cypress types

npm i -D @types/cypress@latest

Upvotes: 16

Neck
Neck

Reputation: 91

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

Upvotes: 0

Related Questions