{"record":{"id":"2ba857121406b98a","repo":"apple/pkl","slug":"cannotresolvedependencynoproject-2ba857","errorCode":"cannotResolveDependencyNoProject","errorMessage":"Cannot resolve dependency because there is no project found.","messagePattern":"Cannot resolve dependency because there is no project found\\.","errorType":"error_code","errorClass":"PackageLoadError","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/util/IoUtils.java","lineNumber":432,"sourceCode":"      return Pair.of(importPath.substring(1), \"/\");\n    }\n    return Pair.of(importPath.substring(1, idx), importPath.substring(idx));\n  }\n\n  private static URI resolveProjectDependency(ModuleKey moduleKey, String notation)\n      throws IOException, ExternalReaderProcessException {\n    var parsed = parseDependencyNotation(notation);\n    var name = parsed.getFirst();\n    var path = parsed.getSecond();\n    var projectDependenciesManager = VmContext.get(null).getProjectDependenciesManager();\n    if (!moduleKey.hasHierarchicalUris() && projectDependenciesManager != null) {\n      throw new PackageLoadError(\n          \"cannotResolveDependencyWithoutHierarchicalUris\",\n          projectDependenciesManager.getProjectFileUri());\n    }\n    if (projectDependenciesManager == null\n        || !projectDependenciesManager.hasUri(moduleKey.getUri())) {\n      throw new PackageLoadError(\"cannotResolveDependencyNoProject\");\n    }\n    var dependency = projectDependenciesManager.getDependencies().get(name);\n    if (dependency != null) {\n      return dependency.getPackageUri().toPackageAssetUri(path).getUri();\n    }\n    throw new PackageLoadError(\"cannotFindDependencyInProject\", name);\n  }\n\n  /**\n   * Resolves {@code importUri} against the module key.\n   *\n   * <p>When {@code importUri} contains a triple-dot, it is resolved if the module key returns true\n   * for both {@link ModuleKey#isLocal()} and {@link ModuleKey#hasHierarchicalUris()}. Otherwise, an\n   * error is thrown.\n   *\n   * <p>When {@code importUri} starts with a {@code @}, it is resolved if the module key supports\n   * dependency notation ()\n   */","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/util/IoUtils.java#L414-L450","documentation":"This PackageLoadError is thrown when a dependency import (`@name/...`) is used but no project is found: there is no ProjectDependenciesManager for the session, or the importing module's URI is not the project's URI scope.","triggerScenarios":"resolveProjectDependency runs with projectDependenciesManager == null (no PklProject loaded, e.g. running `pkl eval` without --project-dir / no PklProject on the module path) or the manager does not recognize moduleKey.getUri().","commonSituations":"Evaluating a file that uses `@dep/...` imports without running from a project directory, or forgetting to pass the project so Pkl can find PklProject.yml.","solutions":["Run from the project directory or pass --project-dir so PklProject is discovered","Ensure the file doing the import lives inside the project covered by PklProject.yml","Declare the dependency in PklProject.yml before importing it"],"exampleFix":"// before\npkl eval ./mod.pkl  # no project loaded\n// after\npkl eval --project-dir . ./mod.pkl","handlingStrategy":"validation","validationCode":"Path projectDir = findPklProject(cwd);\nif (projectDir == null) throw new IllegalStateException(\"@dep/... imports require a PklProject; run with --project-dir\");","typeGuard":null,"tryCatchPattern":"try { pkl eval ... } catch (PackageLoadError e) { if (e.getCode().equals(\"cannotResolveDependencyNoProject\")) { /* instruct user to run from project */ } }","preventionTips":["Always run pkl from a directory containing PklProject.yml (or pass --project-dir)","Declare all @name imports in PklProject.yml dependencies","Verify project detection with `pkl project list`-style tooling before eval"],"tags":["pkl","project","dependencies"],"backgroundTag":"missing-dependency","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"}