{"record":{"id":"b57793ec266142a6","repo":"slint-ui/slint","slug":"could-not-compile-filepath","errorCode":null,"errorMessage":"Could not compile ${filePath}","messagePattern":"Could not compile (.+?)","errorType":"exception","errorClass":"CompileError","httpStatus":null,"severity":"error","filePath":"api/node/typescript/index.ts","lineNumber":340,"sourceCode":"            ? compiler.buildFromPath(filePath)\n            : compiler.buildFromSource(loadData.fileData.source, filePath);\n    const diagnostics = compiler.diagnostics;\n\n    if (diagnostics.length > 0) {\n        const warnings = diagnostics.filter(\n            (d) => d.level === napi.DiagnosticLevel.Warning,\n        );\n\n        if (typeof options !== \"undefined\" && options.quiet !== true) {\n            warnings.forEach((w) => console.warn(\"Warning: \" + w));\n        }\n\n        const errors = diagnostics.filter(\n            (d) => d.level === napi.DiagnosticLevel.Error,\n        );\n\n        if (errors.length > 0) {\n            throw new CompileError(\"Could not compile \" + filePath, errors);\n        }\n    }\n\n    const slint_module = Object.create({});\n\n    // generate structs\n    const structs = compiler.structs;\n\n    for (const key in compiler.structs) {\n        Object.defineProperty(slint_module, translateName(key), {\n            value: function (properties: any) {\n                const defaultObject = structs[key] as any;\n                const newObject = Object.create({});\n\n                for (const propertyKey in defaultObject) {\n                    const propertyName = translateName(propertyKey);\n                    const propertyValue =\n                        properties !== undefined &&","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/slint-ui/slint/blob/a9ea814a5813e7460fa1a867924872095a4d678d/api/node/typescript/index.ts#L322-L358","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nimport { loadFile } from \"slint-ui\";\nconst ui = loadFile(\"app.slint\"); // throws: Could not compile app.slint\n\n// after\nimport { loadFile, CompileError } from \"slint-ui\";\ntry {\n    const ui = loadFile(\"app.slint\");\n} catch (e) {\n    if (e instanceof CompileError) {\n        for (const d of e.diagnostics) {\n            console.error(`[${d.fileName}:${d.lineNumber}:${d.columnNumber}] ${d.message}`);\n        }\n        process.exit(1);\n    }\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isCompileError(e: unknown): e is import(\"slint-ui\").CompileError {\n    return e instanceof Error && (e as any).diagnostics !== undefined;\n}","tryCatchPattern":"try {\n    const ui = loadFile(\"app.slint\");\n} catch (e) {\n    if (e instanceof CompileError) {\n        for (const d of e.diagnostics) console.error(`${d.fileName}:${d.lineNumber}:${d.columnNumber}: ${d.message}`);\n        process.exitCode = 1;\n    } else throw e;\n}","preventionTips":["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."],"tags":["slint","nodejs","compiler","diagnostics","markup"],"backgroundTag":"compile-error-diagnostics","analyzedSha":"a9ea814a5813e7460fa1a867924872095a4d678d","analyzedAt":"2026-08-16T22:39:12.830Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}