Registry / testing / svelte-eslint-parser

svelte-eslint-parser

JSON →
library1.6.0jsnpmunverified

svelte-eslint-parser is the official ESLint parser designed specifically for Svelte applications. It processes `.svelte` files, including their template, script, and style sections, enabling ESLint to analyze and report issues within Svelte's unique syntax. The current stable version is 1.6.0. It follows a release cadence that aligns with new Svelte features and ESLint updates, with minor and patch releases occurring frequently to add support for new Svelte runes, syntax, and improve compatibility with recent ESLint versions. Its key differentiator is its deep integration with Svelte's AST, allowing it to provide a unified parsing experience for both the JavaScript/TypeScript logic and the Svelte-specific template markup, which is crucial for tools like `eslint-plugin-svelte` and `@intlify/eslint-plugin-svelte` to function effectively. The parser is essential for any Svelte project using ESLint for code quality and style enforcement.

npm install svelte-eslint-parser
INSTALL
IMPORT
SIG · SVELTE-ESLINT-PARS
S
svelte-eslint-parser
testingjavascriptv1.6.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

svelteParser
import svelteParser from 'svelte-eslint-parser';
const svelteParser = require('svelte-eslint-parser');
ESLint's modern configuration (eslint.config.js) uses ESM imports. CommonJS `require` is for older configurations.
AST
import type { AST } from 'svelte-eslint-parser';
Importing types for the Svelte AST if you are developing custom ESLint rules or working with the parser's output in TypeScript.
parserOptions
parserOptions: { parser: tsParser, ecmaVersion: 2024, sourceType: 'module' }
This is not a direct import but a common configuration object. `parserOptions.parser` allows specifying a parser for `<script>` blocks, commonly `@typescript-eslint/parser` for TypeScript.

This configuration sets up ESLint with `svelte-eslint-parser` for Svelte 3/4/5 files, including TypeScript support within script blocks.

import js from "@eslint/js"; import svelteParser from "svelte-eslint-parser"; import tsParser from "@typescript-eslint/parser"; export default [ js.configs.recommended, { files: [ "**/*.svelte", // For Svelte 5 runes, specific extensions like .svelte.js/.svelte.ts might be used "**/*.svelte.js", "**/*.svelte.ts" ], languageOptions: { parser: svelteParser, parserOptions: { ecmaVersion: 2024, sourceType: "module", // If using TypeScript in Svelte files, specify @typescript-eslint/parser for the script blocks parser: tsParser, extraFileExtensions: ['.svelte'], // Important for TS plugin to recognize .svelte files project: ['./tsconfig.json'] // Needed for type-aware linting with TS } }, // Optionally add a Svelte ESLint plugin for Svelte-specific rules // plugins: { svelte: sveltePlugin }, // rules: { 'svelte/no-at-html-tags': 'warn' } } ];
Debug
Known issues
breakingWhen migrating to ESLint's new flat configuration (`eslint.config.js`), the `parser` property moves from a top-level `parser` field to `languageOptions.parser` within the configuration object. The `parserOptions` also move under `languageOptions`.
fix
Update your `.eslintrc.*` or `package.json` configurations to use `eslint.config.js` and move parser settings into the `languageOptions` object as shown in the quickstart example.
affects: >=1.0.0
gotchaFor type-aware linting in Svelte components using TypeScript, you must configure `parserOptions.parser` to `@typescript-eslint/parser` and include `extraFileExtensions: ['.svelte']` and `project: ['./tsconfig.json']` within the `parserOptions` to ensure the TypeScript parser correctly processes `.svelte` files and has access to type information.
fix
Ensure your `languageOptions.parserOptions` for Svelte files includes `{ parser: '@typescript-eslint/parser', extraFileExtensions: ['.svelte'], project: './tsconfig.json' }`.
affects: >=1.0.0
gotchaWhen using Svelte 5 with its new rune symbols (`$state`, `$derived`, etc.), it is often necessary to explicitly list extensions like `*.svelte.js` or `*.svelte.ts` in your `files` array within the ESLint configuration, in addition to `*.svelte`.
fix
Adjust the `files` array in your `eslint.config.js` to include `**/*.svelte.js` and `**/*.svelte.ts` for comprehensive coverage of Svelte 5 projects.
affects: >=1.5.0
deprecatedOlder versions of this parser (prior to v1) might have been used with the legacy `.eslintrc.js` or `package.json` ESLint configurations. These older configurations are being phased out by ESLint in favor of flat configurations (`eslint.config.js`).
fix
Migrate your ESLint configuration to the new flat config format (eslint.config.js) for full compatibility and future-proofing, following the official ESLint migration guide and the parser's documentation.
affects: <1.0.0
Errors
Common errors & fixes
ESLint: Cannot read config file: "eslint.config.js" Error: Failed to load parser 'svelte-eslint-parser' from 'eslint.config.js'.
The `svelte-eslint-parser` package is not installed or not accessible in the current environment.
fix
Run `npm install --save-dev svelte-eslint-parser eslint` to install the necessary packages.
Error: Failed to load parser 'svelte-eslint-parser' from 'package.json#eslintConfig.parser'
You are trying to use `svelte-eslint-parser` with a legacy ESLint configuration (e.g., in `package.json` or `.eslintrc.js`) but ESLint requires the new flat configuration (eslint.config.js) for this parser version, or there's a typo in the parser name.
fix
Migrate to the `eslint.config.js` flat configuration format, or check the parser name for typos. If sticking with legacy config (not recommended), ensure ESLint and the parser are compatible versions.
Parsing error: 'import' and 'export' may only appear at the top level (for Svelte files)
Your ESLint configuration's `sourceType` is not set to 'module' for Svelte files, preventing proper parsing of ESM syntax.
fix
In your `languageOptions.parserOptions`, ensure `sourceType: 'module'` is set for the files being parsed by `svelte-eslint-parser`.
Error: You have used a rule which requires parserServices to be generated. You must therefore provide a value for the 'parserOptions.project' property for @typescript-eslint/parser.
You are using a type-aware ESLint rule (likely from `@typescript-eslint/eslint-plugin`) but haven't provided the `project` option for `@typescript-eslint/parser` in your `parserOptions`.
fix
Add `project: ['./tsconfig.json']` to your `languageOptions.parserOptions` when configuring `svelte-eslint-parser` to use `@typescript-eslint/parser` for script blocks. Also, ensure `extraFileExtensions: ['.svelte']` is present.
Upgrade
Version history
1.6.0latest on npm
Audit
Dependencies
svelterequiredPeer dependency required for parsing Svelte syntax. Supports Svelte 3, 4, and 5.
eslintrequiredRequired as the core linting engine that utilizes this parser.
Agent activity
3 hits · last 30 days
node
2
Resources