apple/pkl · error · CliException
noPackageDefinedByProject
noPackageDefinedByProject
Error message
ErrorMessages.create("noPackageDefinedByProject", project.projectFileUri) What it means
Thrown by CliProjectPackager.doRun when a loaded PklProject has no `package` block. Only projects that define a package (name, version, etc. inside the `package {...}` section of PklProject) can be packaged with `pkl project package`. The check is `project.package ?: throw`, so the packaging aborts with the noPackageDefinedByProject message containing the project file URI.
Source
Thrown at pkl-cli/src/main/kotlin/org/pkl/cli/CliProjectPackager.kt:62
CliTestRunner(
cliOptions.copy(sourceModules = normalizeApiTests, projectDir = project.projectDir),
testOptions = testOptions,
consoleWriter = consoleWriter,
errWriter = errWriter,
)
try {
testRunner.run()
} catch (e: CliTestException) {
throw CliException(ErrorMessages.create("packageTestsFailed", project.`package`!!.uri()))
}
}
override fun doRun() {
val projects = buildList {
for (projectFile in normalizedProjectFiles) {
val project = loadProject(projectFile)
project.`package`
?: throw CliException(
ErrorMessages.create("noPackageDefinedByProject", project.projectFileUri)
)
runApiTests(project)
add(project)
}
}
// Require that all local projects are included
projects.forEach { proj ->
proj.dependencies.localDependencies().values.forEach { localDep ->
val projectDir = Path.of(localDep.projectFileUri()).parent
if (projects.none { it.projectDir == projectDir }) {
throw CliException(
ErrorMessages.create("missingProjectInPackageCommand", proj.projectDir, projectDir)
)
}
}
}
ProjectPackager(View on GitHub (pinned to f3efcbfc9b)
Solutions
- Add a `package { name = ...; version = ...; ... }` block to the PklProject file
- Confirm you are packaging the correct project file (the one meant to be published)
- Regenerate the PklProject with `pkl project init` and re-add package metadata
Example fix
// before (PklProject)
project {
name = "myproj"
}
// after
project {
name = "myproj"
}
package {
name = "myproj.pkg"
version = "1.0.0"
} Defensive patterns
Strategy: validation
Validate before calling
grep -q '^package {' PklProject || echo 'no package block: cannot package' Prevention
- Add a package block before attempting to publish
- Only run `pkl project package` on projects intended as packages
When it happens
Trigger: Running `pkl project package <PklProject>` where the PklProject file only contains a `project {}` (or no) declaration and lacks a `package {}` block; passing a dependency-only project file to the packager.
Common situations: Trying to package a plain project (consumer-only) that was never given package metadata; an old PklProject predating packaging support; deleting the package block by accident.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- packageTestsFailed
- missingProjectInPackageCommand
- Node `%s` of type `%s` does not have a property named `%s`.
- Leaf node `%s` of type `%s` does not have a child named `%s`
- Node `%s` of type `%s` does not have a key named `%s`. Avail
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/392e6f333e33d099.
Report an issue: GitHub.