Issue while configuring eslint

Advertisements

I am facing the following issues while adding new commit, I have project configured with eslint + husky + prettier + react + vite

  1:1  error  'vite' should be listed in the project's dependencies, not devDependencies                      import/no-extraneous-dependencies
  2:1  error  '@vitejs/plugin-react-swc' should be listed in the project's dependencies, not devDependencies  import/no-extraneous-dependencies

>Solution :

This can happen due to following:

  1. First and foremost, you are using the eslint-plugin-import which has a rule import/no-extraneous-dependencies.
  2. Second, your ESLint is also checking and validating vite.config.js for the lint errors and your vite.config.js has import statement referring to vite and @vite/plugin-react-swc packages.

Ideally, you should not lint vite.config.js file. You should ignore it completely:

// ESLint - .eslintrc / .eslintrc.js / eslint.config.js
{
  "ignorePatterns": ["vite.config.js", /* other files to ginore */],
  "rules": {
    // ... rules
  }
}

Or, if you still wish to lint the file but resolve this particular error, then you should put the following comment in your vite.config.js file:

// vite.config.js

/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig } from 'vite';

export default defineConfig({
  // Your Vite config...
})

Leave a ReplyCancel reply