eslint-import-resolver-vite

raw JSON →
2.1.1 verified Sat Apr 25 auth: no javascript

Vite module resolution plugin for eslint-plugin-import and eslint-plugin-import-x (resolver interface v3). Current stable version v2.1.1 (released 2025-04). Supports ESM, CJS, and mixed setups. Handles `resolve.alias` from Vite config. Critically, v2.x requires users to provide the config object explicitly, avoiding require() issues in mixed setups. Active development. Key differentiator: lightweight alternative to eslint-import-resolver-typescript when using Vite's alias feature.

error Failed to resolve a module with alias
cause Resolver cannot find the alias mapping because the Vite config is not provided or is incorrect.
fix
Check that you have passed the correct viteConfig object with resolve.alias defined.
error Cannot find module 'eslint-import-resolver-vite'
cause Package not installed or ESLint cannot locate it.
fix
Run npm install --save-dev eslint-import-resolver-vite and ensure the module is in node_modules.
error TypeError: viteConfig is not an object
cause The `viteConfig` option is empty or not an object.
fix
Provide a valid Vite config object: { viteConfig: { resolve: { alias: { ... } } } }
breaking In v2.0.0, the resolver no longer loads the Vite config automatically. You must pass `viteConfig` explicitly.
fix Provide `viteConfig` option: `{ viteConfig: require('./vite.config').config }`
gotcha Mixing ESM and CJS may cause issues when importing the Vite config if it's ESM and you use `require()`. Use dynamic import or provide config as plain object.
fix Use a separate CJS config file or convert to ESM config and use `import()` in a dynamic context.
gotcha The resolver only handles `resolve.alias`; it does not handle Vite plugins or other resolve options.
fix For other custom resolution, consider using eslint-import-resolver-typescript or other resolvers.
deprecated For `eslint-plugin-import-x` resolver interface v2 (deprecated), use default export. For v3, use `createViteImportResolver`.
fix Use `createViteImportResolver` for v3, or upgrade to the latest version of eslint-plugin-import-x.
npm install eslint-import-resolver-vite
yarn add eslint-import-resolver-vite
pnpm add eslint-import-resolver-vite

Setup eslint-import-resolver-vite with a Vite alias config and use it in ESLint settings.

// vite.config.ts
export const viteConfigObj = {
  resolve: {
    alias: {
      _: path.resolve(__dirname, 'src')
    }
  }
};

// .eslintrc.cjs
module.exports = {
  settings: {
    'import/resolver': {
      vite: {
        viteConfig: require('./vite.config').viteConfigObj
      }
    }
  }
};