{"record":{"id":"c253667c2ffd0719","repo":"apple/pkl","slug":"no-project-visible-to-the-working-directory-ensur","errorCode":null,"errorMessage":"No project visible to the working directory. Ensure there is a PklProject file in the workspace, or provide an explicit project directory as an argument.","messagePattern":"No project visible to the working directory\\. Ensure there is a PklProject file in the workspace, or provide an explicit project directory as an argument\\.","errorType":"exception","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"pkl-cli/src/main/kotlin/org/pkl/cli/CliProjectCommand.kt","lineNumber":33,"sourceCode":" */\npackage org.pkl.cli\n\nimport java.nio.file.Files\nimport java.nio.file.Path\nimport org.pkl.commons.cli.CliBaseOptions\nimport org.pkl.commons.cli.CliBaseOptions.Companion.getProjectFile\nimport org.pkl.commons.cli.CliCommand\nimport org.pkl.commons.cli.CliException\nimport org.pkl.core.module.ProjectDependenciesManager.PKL_PROJECT_FILENAME\n\nabstract class CliProjectCommand(cliOptions: CliBaseOptions, private val projectDirs: List<Path>) :\n  CliCommand(cliOptions) {\n\n  protected val normalizedProjectFiles: List<Path> by lazy {\n    if (projectDirs.isEmpty()) {\n      val projectFile =\n        cliOptions.normalizedWorkingDir.getProjectFile(cliOptions.normalizedRootDir)\n          ?: throw CliException(\n            \"No project visible to the working directory. Ensure there is a PklProject file in the workspace, or provide an explicit project directory as an argument.\"\n          )\n      return@lazy listOf(projectFile.normalize())\n    }\n    projectDirs.map(cliOptions.normalizedWorkingDir::resolve).map { dir ->\n      val projectFile = dir.resolve(PKL_PROJECT_FILENAME)\n      if (!Files.exists(projectFile)) {\n        throw CliException(\"Directory $dir does not contain a PklProject file.\")\n      }\n      projectFile.normalize()\n    }\n  }\n}\n","sourceCodeStart":15,"sourceCodeEnd":47,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-cli/src/main/kotlin/org/pkl/cli/CliProjectCommand.kt#L15-L47","documentation":"All `pkl project` subcommands require a visible PklProject file: either explicit project directories were given, or the working directory (searched up to the root dir) contains a PklProject. CliProjectCommand's `normalizedProjectFiles` lazy property throws this when no project can be located.","triggerScenarios":"Running `pkl project ...` (e.g. `pkl project package`) from a directory without a PklProject in it or any ancestor up to normalizedRootDir, and without passing a project directory argument.","commonSituations":"Running the command from a subdirectory whose parents were pruned of PklProject; running from a temp dir or repo root that has no PklProject at top level; forgetting the directory argument after a workspace restructure.","solutions":["Run the command from inside the project directory (where PklProject lives).","Pass the project directory explicitly: `pkl project package path/to/project`.","Create a PklProject file if the project genuinely lacks one (`pkl project init`)."],"exampleFix":"# before (run from repo root without PklProject)\npkl project package\n# after\ncd services/api && pkl project package\n# or\npkl project package services/api","handlingStrategy":"validation","validationCode":"// before invoking any pkl project subcommand\nval cwd = Path.of(\".\").toAbsolutePath()\nval hasProject = generateSequence(cwd) { it.parent }.any { Files.exists(it.resolve(\"PklProject\")) }\ncheck(hasProject) { \"no PklProject visible; pass a project dir explicitly\" }","typeGuard":null,"tryCatchPattern":"try {\n  pklCli.runProject(args)\n} catch (e: CliException) {\n  if (e.message?.startsWith(\"No project visible\") == true) {\n    exec(\"pkl project ... $explicitProjectDir\")\n  } else throw e\n}","preventionTips":["Run `pkl project` commands from a directory containing PklProject.","Pass the project directory explicitly in scripts and CI.","Initialize projects with `pkl project init` before using project subcommands."],"tags":["cli","project","pklproject"],"backgroundTag":"config-file-not-found","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"}