{"record":{"id":"343433d07e3b2c24","repo":"apple/pkl","slug":"cannotfinddependencyinproject","errorCode":"cannotFindDependencyInProject","errorMessage":"Cannot find a dependency named `{0}`, because it is not declared in the current project.","messagePattern":"Cannot find a dependency named `(.+?)`, because it is not declared in the current project\\.","errorType":"error_code","errorClass":"PackageLoadError","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/util/IoUtils.java","lineNumber":438,"sourceCode":"      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   */\n  public static URI resolve(SecurityManager securityManager, ModuleKey moduleKey, URI importUri)\n      throws URISyntaxException,\n          IOException,\n          SecurityManagerException,\n          ExternalReaderProcessException {\n    if (importUri.isAbsolute()) {","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/util/IoUtils.java#L420-L456","documentation":"Thrown when a dependency import names a package that is not present in the current project's declared dependencies. The lookup in projectDependenciesManager.getDependencies() returned null for the requested name.","triggerScenarios":"resolveProjectDependency fails the final lookup: the code after parsing `@name/...` cannot find `name` among the dependencies declared in PklProject.yml.","commonSituations":"Typo in the dependency name in the import (`@mydep/` vs declared `my-dep`), dependency used in code but never added to PklProject.yml dependencies, or stale lockfile after renaming a dependency.","solutions":["Add the dependency to the dependencies section of PklProject.yml (pkl project add is the CLI way)","Fix the name in the import statement to match the declared dependency","Regenerate/update the lockfile after editing PklProject.yml"],"exampleFix":"// before (PklProject.yml has no 'mydep')\nimport \"@mydep/config.pkl\"\n// after\npkl project add mydep@1.0.0\n// then import resolves","handlingStrategy":"validation","validationCode":"for dep in collectDependencyImports(files):\n  if dep not in pklProject.dependencies: raise KeyError(dep)","typeGuard":null,"tryCatchPattern":"try { resolveImport(\"@dep/...\") } catch (PackageLoadError e) { /* print declared dependency names to help fix typo */ }","preventionTips":["Copy dependency names from PklProject.yml verbatim into imports","Use `pkl project add` instead of hand-editing dependency entries","Run `pkl project resolve` after editing dependencies to refresh the lockfile"],"tags":["pkl","dependencies","project"],"backgroundTag":"record-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"}