Volar YAML Language Service
volar-service-yaml is a dedicated Volar plugin designed to integrate the robust `yaml-language-server` into Volar-powered development environments. This integration provides comprehensive language features for YAML files, including syntax highlighting, intelligent auto-completion, real-time schema validation, and diagnostic reporting, directly within projects utilizing Volar's language service, commonly found in Vue.js applications. Currently at version 0.0.70, this package primarily acts as a bridge, enabling sophisticated YAML tooling to function seamlessly within Volar's architecture. Its release cadence is generally synchronized with updates to the main Volar language service (specifically targeting `~2.4.0`), ensuring ongoing compatibility and leveraging an established, widely used YAML language server to offer superior developer experience for YAML configuration files within the Volar ecosystem.
Common errors
-
Error: Cannot find module 'volar-service-yaml'
cause The package is not installed or the import path is incorrect, or there's a module resolution issue in a mixed CJS/ESM project.fixRun `npm install volar-service-yaml` or `yarn add volar-service-yaml`. Double-check the import/require path. If using a custom Volar config, ensure Node.js can resolve the module in that context. -
TypeError: (0 , volar_service_yaml_1.create) is not a function
cause This typically indicates an ESM/CommonJS interop issue where a CommonJS `require` is trying to access a named export like a default export, or vice-versa, or incorrect bundling.fixEnsure you are using the correct import syntax for your module environment. For `volar.config.js`, use `require('volar-service-yaml').create()`. For ESM TypeScript, use `import { create } from 'volar-service-yaml';`. -
Volar service 'yaml' failed to initialize: [...]
cause The underlying `yaml-language-server` might be failing to start or encountering configuration errors.fixCheck your editor's output channels for detailed errors from the Volar language server or the YAML language server. Verify your YAML files for syntax errors or invalid schema references. Ensure no conflicting YAML extensions are active.
Warnings
- breaking This plugin is designed for Volar v2.x and is not compatible with Volar v1.x (or the legacy 'Volar Language Features' VSCode extension). Attempting to use it with older Volar versions will lead to failures.
- gotcha The `volar.config.js` file typically runs in a CommonJS environment, even if your project is otherwise ESM-enabled. Use `require()` for importing plugins within this configuration file.
- gotcha Incorrect or missing YAML schemas can lead to inaccurate diagnostics and missing auto-completion. The YAML Language Server relies on properly configured schemas.
Install
-
npm install volar-service-yaml -
yarn add volar-service-yaml -
pnpm add volar-service-yaml
Imports
- create
import volarServiceYaml from 'volar-service-yaml'; // or import { default as create } from 'volar-service-yaml';import { create } from 'volar-service-yaml'; - create
const create = require('volar-service-yaml').create;const { create } = require('volar-service-yaml'); - ServicePlugin
import type { ServicePlugin } from '@volar/language-service';
Quickstart
/* volar.config.js */
module.exports = {
services: [
require('volar-service-yaml').create(),
],
};
// For a TypeScript-based Volar config (e.g., volar.config.ts with ts-node):
// import { create } from 'volar-service-yaml';
// import type { VolarConfig } from '@volar/language-service';
// export default <VolarConfig>{
// services: [
// create(),
// ],
// };