Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code showing eslint error but vitest is working. 'vi' is not defined

I have the following tsconfig configuration:

{
  "include": ["tests/**/*.ts"],
  "exclude": [],
  "compilerOptions": {
    "composite": true,
    "lib": [],
    "skipLibCheck": true,
    "outDir": "lib",
    "types": ["vitest/globals"]
  }
}

As I have defined types for vitest/globals so yarn vitest cmd is working fine and executing the tests cases as well.

But in VS Code its showing me the following error:

vi is not defined

How I can fix or silence this issue in vs-code?

like image 740
coure2011 Avatar asked Dec 30 '25 07:12

coure2011


2 Answers

I had to add the following to my .eslintrc.json file to fix this issue in a test setup module:

"globals": {
  "vi": true
},

If you're using TypeScript, you should also add the following to your compilerOptions in your tsconfig.json. (You already had this, but I'm mentioning it anyway in case it helps someone else):

"types": ["vitest/globals"]
like image 73
Jim Skerritt Avatar answered Jan 01 '26 15:01

Jim Skerritt


My solution for this problem was to increase the ecmaVersion in the .eslintrc.js file from 2020 to 2022 like this:

"parserOptions": {
  "ecmaVersion": 2022,
}

Since you are using TypeScript, you could also try setting the target to 2022 like this:

"compilerOptions": {
  "target": "ES2022"
}
like image 26
Trojaner_ Avatar answered Jan 01 '26 15:01

Trojaner_