slint-ui/slint · error · CompileError
Could not compile {path}
Error message
Could not compile {path} What it means
slint.load_file()/load_str() compile .slint through the native interpreter and collect diagnostics; warnings are logged (unless quiet=True) and any diagnostic of level Error causes slint.CompileError to be raised with message 'Could not compile <path>'. Each PyDiagnostic in error.diagnostics (also attached as exception notes) carries file, line, column and message pinpointing the failure.
Source
Thrown at api/python/slint/slint/__init__.py:349
if translation_domain is not None:
compiler.translation_domain = translation_domain
result = compiler.build_from_path(Path(path))
diagnostics = result.diagnostics
if diagnostics:
if not quiet:
for diag in diagnostics:
if diag.level == native.DiagnosticLevel.Warning:
_logger.warning(diag)
if diag.level == native.DiagnosticLevel.Note:
_logger.debug(diag)
errors = [
diag for diag in diagnostics if diag.level == native.DiagnosticLevel.Error
]
if errors:
raise CompileError(f"Could not compile {path}", diagnostics)
module = types.SimpleNamespace()
for comp_name in result.component_names:
wrapper_class = _build_class(result.component(comp_name))
setattr(module, comp_name, wrapper_class)
structs, enums = result.structs_and_enums
for name, struct_prototype in structs.items():
name = _normalize_prop(name)
struct_wrapper = _build_struct(name, struct_prototype)
setattr(module, name, struct_wrapper)
for name, enum_class in enums.items():
name = _normalize_prop(name)
setattr(module, name, enum_class)
View on GitHub (pinned to a9ea814a58)
Solutions
- Catch slint.CompileError and print each diagnostic (its str() includes file:line:column and message) to find the exact markup problem.
- Fix the reported locations in the .slint source.
- Ensure imports resolve: run from the right working directory or adjust include paths.
- Validate markup beforehand with the Slint LSP / VS Code extension or slint-viewer.
- Reinstall/upgrade the slint Python package to match the markup's feature level.
Example fix
# before
import slint
module = slint.load_file("app.slint") # raises CompileError
# after
import slint
try:
module = slint.load_file("app.slint")
except slint.CompileError as e:
for diag in e.diagnostics:
print(diag) # [file:line:col] message
raise SystemExit(1) Defensive patterns
Strategy: try-catch
Type guard
def is_compile_error(e: BaseException) -> bool:
return isinstance(e, slint.CompileError) Try / catch
try:
module = slint.load_file("app.slint")
except slint.CompileError as e:
for diag in e.diagnostics:
print(diag) # [file:line:col] message
raise SystemExit(1) Prevention
- Validate .slint in CI with the Slint LSP or slint-viewer before Python loads it.
- Load files from stable absolute paths or set include paths so imports resolve.
- Upgrade the slint package and .slint markup together.
When it happens
Trigger: Calling slint.load_file("app.slint") (or load_str) on markup with syntax errors, unknown elements/properties, type mismatches, or unresolvable imports; also when an imported file is missing from the include paths.
Common situations: Typos in .slint, renamed APIs after a slint-python upgrade, wrong relative import paths, styles not installed, or loading a file written for a newer Slint version.
Related errors
- Could not compile ${filePath}
- 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
- 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/8b717858e30003d1.
Report an issue: GitHub.