Vue Language Server (VLS)
The `vls` (Vue Language Server) package provides a Language Server Protocol (LSP) implementation specifically for Vue.js projects. Its primary role was to power editor extensions like Vetur in VS Code, offering features such as intelligent code completion, diagnostics, syntax highlighting, and formatting for Vue Single File Components (SFCs). The `vls` npm package itself is currently at version `0.8.5` and has not received significant updates for several years, indicating a stagnant development pace for the standalone package. While Vetur, which historically consumed `vls`, continued to evolve for a time (reaching versions like `0.37.x`), the broader Vue ecosystem, particularly with the advent of Vue 3, has largely transitioned to Volar as the recommended language server due to its more comprehensive and official support for modern Vue 3 features like `<script setup>` and enhanced TypeScript integration. As a result, `vls` is primarily relevant for older Vue 2 projects or as a foundational component for historical language tooling, with limited utility for current Vue 3 development.
Common errors
-
vls: command not found
cause The `vls` executable is not installed globally or is not in the system's PATH.fixInstall `vls` globally using `npm install -g vls` or `yarn global add vls`. -
Error: Cannot find module 'vls/dist/vueServerMain'
cause A language client attempted to resolve the `vueServerMain` entry point but `vls` is not installed as a local dependency or the path is incorrect.fixEnsure `vls` is installed as a local dependency (`npm install vls --save` or `yarn add vls`) in the project where the language client is running.
Warnings
- breaking The `vls` package, and by extension the Vetur VS Code extension it powered, provides only basic and incomplete support for modern Vue 3 features, particularly `<script setup>`, Composition API refinements, and advanced TypeScript integration. Many Vue 3-specific language features will not function correctly or at all.
- deprecated The `vls` npm package at version `0.8.5` has not been updated for an extended period and is considered deprecated for modern Vue.js development. While the Vetur extension historically used `vls` as its core, Vetur itself now explicitly recommends Volar for Vue 3 projects, indicating a shift in the ecosystem.
- gotcha The `vls` package explicitly requires Node.js version `10` or higher to run, as specified in its `engines` field. Attempting to run `vls` with older Node.js versions will prevent the language server from starting or cause unexpected errors.
Install
-
npm install vls -
yarn add vls -
pnpm add vls
Imports
- vls (CLI command)
import { vls } from 'vls'npm install -g vls vls --version
- vueServerMain
import { vueServerMain } from 'vls/dist/vueServerMain'require.resolve('vls/dist/vueServerMain') - VLS (type)
import { VLS } from 'vls'import type { VLS } from 'vls'
Quickstart
npm install -g vls
# Verify installation and server functionality
vls --version
# Example of how a language client might launch it (conceptual)
const { spawn } = require('child_process');
const path = require('path');
const vlsPath = require.resolve('vls/dist/vueServerMain');
console.log(`Attempting to start VLS from: ${vlsPath}`);
const serverProcess = spawn('node', [vlsPath], {
stdio: ['pipe', 'pipe', 'pipe'] // stdin, stdout, stderr for LSP communication
});
serverProcess.stdout.on('data', (data) => {
console.log(`VLS STDOUT: ${data.toString().trim()}`);
});
serverProcess.stderr.on('data', (data) => {
console.error(`VLS STDERR: ${data.toString().trim()}`);
});
serverProcess.on('exit', (code) => {
console.log(`VLS process exited with code ${code}`);
});
// In a real client, you'd send LSP messages to serverProcess.stdin
// and parse responses from serverProcess.stdout.