0

UPDATE: This error comes from the auto import of cy from the date-fns library, which also has a cy of it's own. I've just commented it out in my code, since I don't necessarily want to get rid of auto-importing.

For some reason, every now and then I will get an error in my cypress tests _locale.cy.visit is not a function. I've read some past posts on this and people say that removing the import { cy } from "date-fns/locale" will also remove the error. However, when I edit the test, it will be auto-imported and the error will happen again every now and then.

Is there anyway to remove this permanently or a better work around then constantly removing it?|

Any tips or advice would be greatly appreciated!

enter image description here

LovelyAndy
  • 841
  • 8
  • 22

3 Answers3

4

Maybe the trick is to ensure VSCode already knows about the Cypress version of cy.

In my tsconfig.json I have a "types": ["cypress"] configuration

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

Not sure if that is the key to your problem. Please reload VSCode after making the change.

Fody
  • 23,754
  • 3
  • 20
  • 37
1

I would suggest you disable the auto-import from your VS Code. To do that go to File > Preferences > Settings or Code > Preferences > Settings and write:

//For js
"javascript.suggest.autoImports": false

//For TS
"typescript.suggest.autoImports": false 
Alapan Das
  • 17,144
  • 3
  • 29
  • 52
0

If you do not use typescript you can configure it via jsconfig.json like this:

{
  ...
  "compilerOptions": {
    "types": ["cypress"]
  }
  ...
}
Andi
  • 1,172
  • 1
  • 11
  • 16