apple/pkl · error · CliException
Output file `$outputFile` is a directory. Did you mean `--mu
Error message
Output file `$outputFile` is a directory. Did you mean `--multiple-file-output-path`?
What it means
In single-file output mode, CliEvaluator.writeOutput checks whether the target output path is an existing directory before writing; if so it throws this error and hints that the user probably intended multiple-file output mode. This happens because evaluating `output.files` output into a single output path doesn't make sense.
Source
Thrown at pkl-cli/src/main/kotlin/org/pkl/cli/CliEvaluator.kt:167
return evaluateExpressionString(moduleSource, options.expression)
.toByteArray(StandardCharsets.UTF_8)
}
/** Renders each module's `output.bytes`, writing it to the specified output file. */
private fun writeOutput(builder: EvaluatorBuilder) {
val evaluator = builder.setOutputFormat(options.outputFormat).build()
evaluator.use { ev ->
val outputFiles = fileOutputPaths
if (outputFiles != null) {
// files that we've written non-empty output to
// YamlRenderer produces empty output if `isStream` is true and `output.value` is empty
// collection
val writtenFiles = mutableSetOf<Path>()
for ((moduleUri, outputFile) in outputFiles) {
val moduleSource = toModuleSource(moduleUri, inputStream)
if (Files.isDirectory(outputFile)) {
throw CliException(
"Output file `$outputFile` is a directory. " +
"Did you mean `--multiple-file-output-path`?"
)
}
val output = ev.evalOutput(moduleSource)
outputFile.createParentDirectories()
if (!writtenFiles.contains(outputFile)) {
// write file even if output is empty to overwrite output from previous runs
outputFile.writeBytes(output)
if (output.isNotEmpty()) {
writtenFiles.add(outputFile)
}
} else {
if (output.isNotEmpty()) {
outputFile.writeString(
options.moduleOutputSeparator + '\n',
Charsets.UTF_8,
StandardOpenOption.WRITE,View on GitHub (pinned to f3efcbfc9b)
Solutions
- If you intended multiple-file output, use `--multiple-file-output-path` instead.
- Otherwise, specify a file path (not an existing directory) as the output, or delete/rename the directory.
- Fix shell scripts to pass a concrete file path for single-file output.
- Clean output directories between runs.
Example fix
# before $ pkl eval mymod.pkl out/ # out/ is a directory # after $ pkl eval mymod.pkl --multiple-file-output-path out/
Defensive patterns
Strategy: validation
Validate before calling
import java.nio.file.Files
import java.nio.file.Path
require(!Files.isDirectory(Path.of(outputFile))) { "Output path $outputFile is a directory; use --multiple-file-output-path" } Try / catch
try {
ev.writeOutput(...)
} catch (e: CliException) {
if (e.message?.contains("multiple-file-output-path") == true) {
// rerun with --multiple-file-output-path
}
} Prevention
- Pass a file path for single-file output and a directory only with --multiple-file-output-path.
- Avoid reusing multi-file output directories as single-file output targets.
- Quote and verify output path variables in shell scripts.
When it happens
Trigger: Running a command whose evaluated output is written to a path that already exists as a directory — e.g. passing a directory to the plain output path argument, or re-running against a directory produced by a previous --multiple-file-output-path run.
Common situations: Mixing single-file and multiple-file output invocations on the same path; typos in the output path argument (pointing at a directory instead of a file); shell scripts that pass $OUTPUT_DIR where a file is expected.
Related errors
- Output path `$outputDir` exists and is not a directory.
- Output path `$outputDir` exists and is not a directory.
- Output file conflict: `output.files` entries `"${previousOut
- Output file conflict: `output.files` entry `"$pathSpec"` res
- Cannot substitute output path placeholder `%{moduleDir}` bec
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/c745a4dcedde43f3.
Report an issue: GitHub.