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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
startLanguageServer
✓ import { startLanguageServer } from 'langium';
✗ const { startLanguageServer } = require('langium');
This function initiates the Language Server Protocol (LSP) server based on the provided shared services. Langium is ESM-first.
NodeFileSystem
✓ import { NodeFileSystem } from 'langium/node';
✗ import { NodeFileSystem } from 'langium';
Used for file system access in Node.js environments. For browser environments, use `EmptyFileSystem` from 'langium'.
LangiumServices
✓ import { LangiumServices, LangiumSharedServices, Module } from 'langium';
✗ import { ILangiumServices } from 'langium';
These are core types for defining and configuring language-specific and shared services within Langium's dependency injection system. Renamed from `ILangiumServices` in older versions.
createMyLanguageServices
✓ import { createMyLanguageServices } from './my-language-module';
This symbol represents a common pattern where `langium-cli` generates a language-specific factory function for setting up services (e.g., `createHelloWorldServices`). The actual import path and name will vary based on your project structure and language name.
Demonstrates a minimal Langium language server setup, showing how to establish an LSP connection and start the server using generated service factories.
import { startLanguageServer, EmptyFileSystem, LangiumSharedServices } from 'langium';
import { NodeFileSystem } from 'langium/node';
import { createConnection, ProposedFeatures } from 'vscode-languageserver/node';
// --- This part of the code is typically generated by `langium-cli` ---
// It sets up your language's grammar, parser, validator, and other services.
// For a runnable example, we'll mock a simple `createMyLanguageServices`.
interface MyLanguageServices {
// Define your language-specific service interfaces here
// e.g., validation: { MyLanguageValidator: MyLanguageValidator }
}
function createMyLanguageServices(context: {
connection?: ReturnType<typeof createConnection>;
fileSystem: EmptyFileSystem | NodeFileSystem;
}): { shared: LangiumSharedServices; MyLanguage: MyLanguageServices } {
// In a real Langium project, this would load your grammar and hook up
// the generated parser, linker, scope provider, etc.
// For this quickstart, we're providing a basic mock.
const connection = context.connection ?? createConnection(ProposedFeatures.all);
// Mimic the creation of default shared services
const shared = require('langium/lib/shared/shared-module').createDefaultSharedModule(context);
// Mimic the creation of language-specific services
const MyLanguage: MyLanguageServices = {}; // Empty mock for demonstration
connection.onInitialize(() => {
// In a real setup, capabilities would be dynamically provided by Langium
return {
capabilities: {
textDocumentSync: { openClose: true, change: 1 /* TextDocumentSyncKind.Full */ },
completionProvider: { resolveProvider: true, triggerCharacters: ['.'] },
hoverProvider: true
}
};
});
connection.onInitialized(() => {
connection.console.log('Mock Langium language server initialized for MyLanguage.');
});
return { shared, MyLanguage };
}
// ------------------------------------------------------------------
// Establish a connection for the language server.
// Langium typically uses Node's IPC to communicate with the VS Code client.
const connection = createConnection(ProposedFeatures.all);
// Create the shared and language-specific services.
// `createMyLanguageServices` would be imported from your generated module file (e.g., `./src/language-server/my-language-module.ts`).
// The NodeFileSystem is crucial for server-side file access.
const { shared, MyLanguage } = createMyLanguageServices({ connection, ...NodeFileSystem });
// Start the language server.
// This function handles the lifecycle of the LSP connection and dispatches requests
// to the services configured in `shared`.
startLanguageServer(shared);
// Listen for incoming LSP messages.
connection.listen();
langium --version
Errors
Common errors & fixes
Cannot find module 'vscode-languageserver/node' or its corresponding type declarations.
The `vscode-languageserver` package, essential for LSP functionality, is not installed or incorrectly imported for a Node.js environment.
fixInstall the package: `npm install vscode-languageserver vscode-languageserver-types vscode-languageserver-protocol`. Ensure you are importing `vscode-languageserver/node` for Node.js servers, or `vscode-languageserver/browser` for browser-based servers.
TypeError: Cannot read properties of undefined (reading 'validation') (or similar access on a service property)
A Langium service, or a property within a service, has not been correctly registered in the dependency injection module or accessed before its initialization.
fixVerify your `_module.ts` file correctly registers all necessary services (default and custom). Ensure that custom services that depend on `LangiumServices` are properly constructed, typically by accepting `services: YourLanguageServices` in their constructor.
Error: Node.js version X.Y.Z is not supported. Langium requires >=20.10.0
The installed Node.js version is older than the minimum required by Langium.
fixUpgrade your Node.js version to 20.10.0 or newer. Tools like `nvm` (Node Version Manager) can help manage multiple Node.js versions.
Error: The Langium grammar 'MyLanguage' cannot be loaded. Ensure the grammar has been generated and compiled.
The `langium-cli` generation step has not been run, or the generated TypeScript files have not been compiled, meaning the grammar definition is not available at runtime.
fixRun `npm run langium:generate` (or `npx langium generate`) to generate the grammar-related TypeScript files, then `npm run build` (or `tsc`) to compile them. Verify the `langium:generate` script in `package.json` points to the correct grammar file.
Audit
Dependencies
vscode-languageserverrequiredProvides core Language Server Protocol (LSP) functionality for integration with IDEs.
langium-clirequiredCommand-line interface for processing Langium grammars and generating TypeScript code.
yooptionalYeoman generator tool used to scaffold new Langium language extension projects.
generator-langiumoptionalYeoman generator specifically for creating Langium projects.