slint-ui/slint · error · CompileError
Could not compile ${filePath}
Error message
Could not compile ${filePath} What it means
The Node.js slint API (loadFile/loadSource in api/node/typescript/index.ts) compiles .slint markup at runtime through the native ComponentCompiler. After buildFromPath/buildFromSource, it filters the compiler diagnostics; if any diagnostic has level Error, it throws a CompileError whose message is 'Could not compile <filePath>' plus a formatted list of every diagnostic (file:line:column + message). The raw napi.Diagnostic array stays available on error.diagnostics.
Source
Thrown at api/node/typescript/index.ts:340
? compiler.buildFromPath(filePath)
: compiler.buildFromSource(loadData.fileData.source, filePath);
const diagnostics = compiler.diagnostics;
if (diagnostics.length > 0) {
const warnings = diagnostics.filter(
(d) => d.level === napi.DiagnosticLevel.Warning,
);
if (typeof options !== "undefined" && options.quiet !== true) {
warnings.forEach((w) => console.warn("Warning: " + w));
}
const errors = diagnostics.filter(
(d) => d.level === napi.DiagnosticLevel.Error,
);
if (errors.length > 0) {
throw new CompileError("Could not compile " + filePath, errors);
}
}
const slint_module = Object.create({});
// generate structs
const structs = compiler.structs;
for (const key in compiler.structs) {
Object.defineProperty(slint_module, translateName(key), {
value: function (properties: any) {
const defaultObject = structs[key] as any;
const newObject = Object.create({});
for (const propertyKey in defaultObject) {
const propertyName = translateName(propertyKey);
const propertyValue =
properties !== undefined &&View on GitHub (pinned to a9ea814a58)
Solutions
- Catch the CompileError and read error.diagnostics (fileName, lineNumber, columnNumber, message) to locate each problem in the markup.
- Fix the reported .slint location(s): spelling of elements/properties, property value types, or missing imports.
- If imports fail, pass correct includePaths (and libraryPaths for @library imports) in the LoadFileOptions argument.
- Pre-check the file outside Node with `cargo run --bin slint-viewer -- app.slint` or the Slint LSP/VS Code extension.
- Pin the slint-ui npm version that matches the .slint feature set you use.
Example fix
// before
import { loadFile } from "slint-ui";
const ui = loadFile("app.slint"); // throws: Could not compile app.slint
// after
import { loadFile, CompileError } from "slint-ui";
try {
const ui = loadFile("app.slint");
} catch (e) {
if (e instanceof CompileError) {
for (const d of e.diagnostics) {
console.error(`[${d.fileName}:${d.lineNumber}:${d.columnNumber}] ${d.message}`);
}
process.exit(1);
}
throw e;
} Defensive patterns
Strategy: try-catch
Type guard
function isCompileError(e: unknown): e is import("slint-ui").CompileError {
return e instanceof Error && (e as any).diagnostics !== undefined;
} Try / catch
try {
const ui = loadFile("app.slint");
} catch (e) {
if (e instanceof CompileError) {
for (const d of e.diagnostics) console.error(`${d.fileName}:${d.lineNumber}:${d.columnNumber}: ${d.message}`);
process.exitCode = 1;
} else throw e;
} Prevention
- Run the .slint through slint-viewer or the Slint LSP in CI before the Node app loads it.
- Always pass includePaths when imports live outside the file's directory.
- Pin the slint-ui version and upgrade .slint and package together.
When it happens
Trigger: Calling loadFile("app.slint") or loadSource(source, filePath) with markup that fails to compile: syntax errors, unknown elements or properties, wrong property types, unresolved `import { X } from "..."` files, or referencing widgets from a style that is not set via the style option.
Common situations: Typos in element/property names in .slint; imports of files not covered by the includePaths option; upgrading slint-ui to a version that renamed or removed properties; CI running with a different widget style default; passing a wrong absolute/relative path so imported files cannot be found.
Related errors
- Could not compile {path}
- slint-ui-dev must not be imported directly — it only provide
- Callback '{name}' in global '{global_name}' cannot be used w
- Callback '{name}' in global '{global_name}' cannot be used w
- Callback '{name}' cannot be used with a callback decorator f
AI-assisted analysis of slint-ui/slint@a9ea814a58 (2026-08-16).
Data as JSON: /api/errors/b57793ec266142a6.
Report an issue: GitHub.