Registry / http-networking / svelte-language-server

svelte-language-server

JSON →
library0.17.30jsnpmunverified

The Svelte Language Server (package `svelte-language-server`, currently at version 0.17.30) provides language-specific smarts for Svelte development within various editors by implementing the Language Server Protocol (LSP). It acts as the core engine for features like diagnostics, autocompletion, hover information, formatting, and code actions for Svelte, HTML, CSS/SCSS/LESS, and TypeScript/JavaScript within Svelte components. It is an actively maintained component of the broader `sveltejs/language-tools` monorepo, with frequent patch releases addressing performance improvements and bug fixes, typically on a weekly or bi-weekly cadence. Key differentiators include its deep integration with the Svelte compiler and TypeScript, leveraging `svelte2tsx` for seamless type-checking, and its ability to provide comprehensive language features across multiple embedded languages within `.svelte` files. Unlike many libraries consumed directly via `import`, this package is primarily designed to be run as a separate process by editor extensions (like the official VS Code Svelte extension) or custom LSP clients, offering a robust and extensible foundation for Svelte tooling. Its current stable versions require Node.js >= 18.0.0.

npm install svelte-language-server
INSTALL
IMPORT
SIG · SVELTE-LANGUAGE-SE
S
svelte-language-server
http-networkingjavascriptv0.17.30
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.

LSConfigManager
import { LSConfigManager } from 'svelte-language-server'
For programmatic access to the language server's configuration manager, useful for custom tooling or extensions.
SvelteDocument
import { SvelteDocument } from 'svelte-language-server'
Represents a Svelte file within the language server's document model, useful for advanced programmatic interactions.
SveltePlugin
import { SveltePlugin } from 'svelte-language-server'
The base class for language server plugins, used when extending the server's capabilities with custom language features.

Demonstrates how to launch the Svelte Language Server as a child process and send an `initialize` request, illustrating basic programmatic interaction for building an LSP client.

import { spawn } from 'child_process'; import { resolve } from 'path'; // This quickstart demonstrates how to programmatically launch the Svelte Language Server // and send an 'initialize' request, as a basic example for building an LSP client. // In a typical setup, users interact via editor extensions (e.g., VS Code Svelte extension). const serverExecutable = resolve(__dirname, 'node_modules', 'svelte-language-server', 'bin', 'server.js'); // Spawn the language server process const lsProcess = spawn('node', [serverExecutable], { stdio: ['pipe', 'pipe', 'pipe'] // stdin, stdout, stderr pipes }); let requestId = 1; function sendLSPRequest(method: string, params: any) { const request = { jsonrpc: '2.0', id: requestId++, method, params }; const jsonRequest = JSON.stringify(request); const contentLength = Buffer.byteLength(jsonRequest, 'utf8'); const header = `Content-Length: ${contentLength}\r\n\r\n`; // Simplified header lsProcess.stdin.write(header + jsonRequest); } // Listen for responses (simplified, real clients handle streaming and headers) lsProcess.stdout.on('data', (data) => { console.log('Language Server Output:', data.toString().trim()); }); lsProcess.stderr.on('data', (data) => { console.error('Language Server Error:', data.toString().trim()); }); lsProcess.on('close', (code) => { console.log(`Language Server process exited with code ${code}`); }); // Send the initial 'initialize' request, crucial for LSP setup sendLSPRequest('initialize', { processId: process.pid, clientInfo: { name: 'Svelte LS Quickstart', version: '1.0' }, rootUri: 'file:///home/user/my-svelte-project', // Replace with actual project root capabilities: {}, // Define client capabilities as per LSP spec initializationOptions: { // Pass initial configuration configuration: { svelte: { plugin: { typescript: { enable: true }, html: { enable: true } }, // Other Svelte language server specific settings }, typescript: { /* TypeScript specific settings */ }, javascript: { /* JavaScript specific settings */ }, } } }); // In a real application, you would continue to send requests (e.g., didOpen, textDocument/hover) // and handle responses. For this quickstart, we'll just demonstrate initialization. // Ensure to properly manage the lifecycle of the child process. process.on('exit', () => lsProcess.kill()); // Clean up on parent exit
Debug
Known issues
breakingAs of `svelte-language-server@0.17.0` (part of `language-tools` v100.1.0), the minimum Node.js version required is 18.0.0. Older Node.js versions will prevent the server from starting.
fix
Upgrade your Node.js environment to version 18.0.0 or higher.
affects: >=0.17.0
gotchaThe language server's configuration is highly customizable. Incorrect or conflicting settings, especially those related to TypeScript, CSS preprocessors, or formatting (Prettier), can lead to unexpected behavior or disabled features.
fix
Refer to the official documentation for `svelte-language-server` settings and the `svelte-vscode` extension settings for common configurations. Use the `initializationOptions.configuration` object for programmatic setup.
affects: >=0.1.0
gotchaThe `typescript` package is a peer dependency. If it's not installed in your project or if an incompatible version is present, TypeScript-related language features (diagnostics, autocompletion for TS/JS) will not function correctly.
fix
Ensure `typescript` is installed in your project's `devDependencies` (e.g., `npm install -D typescript@^5.0.0`) and that its version is compatible with the language server's requirements.
affects: >=0.1.0
gotchaPerformance issues in large Svelte projects can arise if the language server is not properly configured with workspace exclusions (e.g., `node_modules`, `dist` directories) or if `svelte-check` is run without `--incremental` flags where applicable.
fix
Configure `svelte.plugin.typescript.workspace.exclude` and similar options in your editor or language server initialization options. For CI/CD, use `svelte-check --incremental`.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'typescript' or its corresponding type declarations.
The `typescript` package is a peer dependency but is not installed or not resolvable in the project.
fix
Install TypeScript in your project: `npm install -D typescript` or `yarn add -D typescript`.
The Svelte Language Server process terminated unexpectedly with exit code X.
This generic error often indicates an unhandled exception within the server or an incompatible Node.js environment.
fix
Check your Node.js version (must be >= 18.0.0). Inspect the server's `stderr` output for more specific error messages if available.
Could not resolve Svelte files with NodeNext in --incremental/tsgo mode.
This was a known bug in older versions related to module resolution strategies in specific TypeScript environments.
fix
Update `svelte-language-server` to version `0.17.30` or newer, as this issue has been addressed in recent patches. Ensure your `tsconfig.json`'s `moduleResolution` is correctly configured.
TypeScript/JavaScript features (diagnostics, autocompletion) are not working in Svelte files.
The TypeScript plugin within the language server might be disabled or misconfigured, or there's an issue with the underlying TypeScript installation.
fix
Ensure `svelte.plugin.typescript.enable` is set to `true` in your language server configuration (e.g., editor settings). Verify your TypeScript installation and version.
Upgrade
Version history
0.17.30latest on npm
Audit
Dependencies
typescriptrequiredRequired for TypeScript and JavaScript language features; listed as a peer dependency.
svelte2tsxrequiredInternal dependency for transforming Svelte code into TypeScript for type-checking.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources