eslint-plugin-svelte
raw JSON → 3.17.1 verified Sat Apr 25 auth: no javascript
Official ESLint plugin for Svelte that leverages AST from svelte-eslint-parser. Current stable version is 3.17.1, with active release cadence (multiple minor/patch releases per month). Provides 80+ rules covering accessibility, best practices, style, and Svelte-specific patterns. Supports Svelte 3, 4, and 5. Requires ESLint v8.57.1+, v9+ or v10+. Ships TypeScript definitions. Recommended over deprecated eslint-plugin-svelte3. Integrates with flat config (eslint.config.js) and provides recommended configs.
Common errors
error Error: Cannot find module 'eslint-plugin-svelte' ↓
cause Plugin is not installed or is in devDependencies but ESLint is running globally or in different context.
fix
Run
npm install --save-dev eslint-plugin-svelte or ensure ESLint is run from the project root with correct node_modules. error Configuration for rule 'svelte/valid-compile' is invalid: Value "error" is not allowed. ↓
cause The rule 'valid-compile' does not exist; it was renamed or removed in v3.
fix
Use 'svelte/valid-prop' or check rule list. Remove 'svelte/valid-compile' from config.
error ESLint couldn't determine the plugin 'svelte' uniquely. This may be caused by an incorrectly installed plugin. ↓
cause Multiple versions or conflicting installations of eslint-plugin-svelte (e.g., both CJS and ESM).
fix
Ensure only one version is installed:
npm dedupe or npx eslint --ext .svelte --resolve-plugins-relative-to . error Parsing error: Unexpected token '{' ↓
cause The parser (svelte-eslint-parser) is not configured correctly; often missing parserOptions.svelteConfig for Svelte 5 runes.
fix
Set parserOptions.svelteConfig in eslint.config.js:
parserOptions: { svelteConfig: './svelte.config.js' }. error Error: Unexpected top-level token in Svelte component ↓
cause Using a Svelte 5 rune ($state, $derived) without proper parser support or svelte.config.js import.
fix
Update svelte-eslint-parser and eslint-plugin-svelte to latest, and import svelte.config.js in eslint.config.js.
Warnings
breaking eslint-plugin-svelte >= 2.0.0 no longer supports CommonJS require(). Use ESM imports only. ↓
fix Use `import svelte from 'eslint-plugin-svelte'` in eslint.config.js.
deprecated eslint-plugin-svelte3 is deprecated. Use eslint-plugin-svelte instead. ↓
fix Uninstall eslint-plugin-svelte3 and install eslint-plugin-svelte. See migration guide.
gotcha Flat config (eslint.config.js) is required for v3+. The plugin no longer supports .eslintrc files. ↓
fix Migrate to eslint.config.js with `import svelte from 'eslint-plugin-svelte'`.
gotcha svelte.config.js must be imported in eslint.config.js if using runes or Svelte 5 features; otherwise parser may fail. ↓
fix Add `import svelteConfig from './svelte.config.js'` and set `parserOptions.svelteConfig`.
gotcha When using TypeScript, you must set `parserOptions.parser` to the TypeScript parser (e.g., `typescript-eslint/parser`). ↓
fix In eslint.config.js for `.svelte` files, add `languageOptions: { parserOptions: { parser: ts.parser } }`.
Install
npm install eslint-plugin-svelte yarn add eslint-plugin-svelte pnpm add eslint-plugin-svelte Imports
- default wrong
const svelte = require('eslint-plugin-svelte')correctimport svelte from 'eslint-plugin-svelte' - defineConfig
import { defineConfig } from 'eslint/config' - configs wrong
import { configs } from 'eslint-plugin-svelte'correctimport svelte from 'eslint-plugin-svelte'; export default [... svelte.configs.recommended, ...]
Quickstart
// eslint.config.js
import svelte from 'eslint-plugin-svelte';
import globals from 'globals';
import ts from 'typescript-eslint';
export default [
{
ignores: ['build/', 'dist/', 'node_modules/']
},
...ts.configs.recommended,
...svelte.configs.recommended,
{
languageOptions: {
globals: {
...globals.browser,
...globals.node
}
}
},
{
files: ['**/*.svelte', '**/*.svelte.ts'],
languageOptions: {
parserOptions: {
parser: ts.parser
}
}
}
];