{"record":{"id":"0c488b5cd5fb2ce4","repo":"apple/pkl","slug":"cannotexportvalue","errorCode":"cannotExportValue","errorMessage":"cannotExportValue","messagePattern":"cannotExportValue","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/VmFunction.java","lineNumber":179,"sourceCode":"\n  @Override\n  public VmClass getVmClass() {\n    return BaseModule.getFunctionNClass(paramCount);\n  }\n\n  @Override\n  public void force(boolean allowUndefinedValues, boolean recurse) {\n    // do nothing\n  }\n\n  @Override\n  public void force(boolean allowUndefinedValues) {\n    // do nothing\n  }\n\n  @Override\n  public Object export() {\n    throw new VmExceptionBuilder().evalError(\"cannotExportValue\", getVmClass()).build();\n  }\n\n  @Override\n  public void accept(VmValueVisitor visitor) {\n    visitor.visitFunction(this);\n  }\n\n  @Override\n  public <T> T accept(VmValueConverter<T> converter, Iterable<Object> path) {\n    return converter.convertFunction(this, path);\n  }\n\n  @Override\n  public boolean equals(Object obj) {\n    return this == obj;\n  }\n\n  @Override","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/VmFunction.java#L161-L197","documentation":"VmFunction.export() always throws an evalError 'cannotExportValue': function values have no externalizable representation, so forcing a function into an exported/host value (e.g. as module output or via PValue conversion) is unsupported. The input at fault is a Function-typed value placed where a data value is expected.","triggerScenarios":"A module's output contains a function value, e.g. `output { value = someFunction }` or a top-level binding that resolves to a function when the module is evaluated/exported (via pkl CLI or the Java API export()).","commonSituations":"Assigning a function to `output.value` by mistake; exporting an object whose property is a function; accidentally referencing a function name without calling it.","solutions":["Export a plain data value instead of a function (e.g. call the function and output its result).","Remove functions from the `output.value` of modules consumed externally."],"exampleFix":"// before\noutput { value = toUpper }\n// after\noutput { value = toUpper(\"hello\") }","handlingStrategy":"validation","validationCode":"if (typeof output.value === 'function') throw new Error('cannot export a function; call it and export the result')","typeGuard":"const isExportable = (v) => v === null || ['string','number','boolean'].includes(typeof v) || Array.isArray(v) || (typeof v === 'object' && !('call' in v));","tryCatchPattern":"try { module.export() } catch (e) { if (e.code === 'cannotExportValue') { console.error('output contains a function:', e.vmClass) } throw e }","preventionTips":["Never assign a function directly to output.value","Call functions when building the exported value","Keep exported objects free of function-typed properties"],"tags":["pkl","export","function"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}