{"record":{"id":"a118926d215239cf","repo":"apple/pkl","slug":"cannotfinddependencyinpackage","errorCode":"cannotFindDependencyInPackage","errorMessage":"cannotFindDependencyInPackage","messagePattern":"cannotFindDependencyInPackage","errorType":"error_code","errorClass":"PackageLoadError","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/module/ModuleKeys.java","lineNumber":633,"sourceCode":"    }\n\n    @Override\n    public URI getUri() {\n      return packageAssetUri.getUri();\n    }\n\n    @Override\n    public URI resolveUri(URI baseUri, URI importUri) throws IOException, SecurityManagerException {\n      var ssp = importUri.getSchemeSpecificPart();\n      if (importUri.isAbsolute() || !ssp.startsWith(\"@\")) {\n        return ModuleKey.super.resolveUri(baseUri, importUri);\n      }\n      var parsed = IoUtils.parseDependencyNotation(ssp);\n      var name = parsed.getFirst();\n      var path = parsed.getSecond();\n      var dependency = getDependencies().get(name);\n      if (dependency == null) {\n        throw new PackageLoadError(\n            \"cannotFindDependencyInPackage\",\n            name,\n            packageAssetUri.getPackageUri().getDisplayName());\n      }\n      return dependency.getPackageUri().toPackageAssetUri(path).getUri();\n    }\n  }\n\n  /** Represents a module imported via the {@code package} scheme. */\n  private static class Package extends AbstractPackage {\n\n    Package(PackageAssetUri packageAssetUri) {\n      super(packageAssetUri);\n    }\n\n    private PackageResolver getPackageResolver() {\n      var packageResolver = VmContext.get(null).getPackageResolver();\n      assert packageResolver != null;","sourceCodeStart":615,"sourceCodeEnd":651,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/module/ModuleKeys.java#L615-L651","documentation":"When resolving a dependency notation like '@name/path', ModuleKeys looks the package name up in the project's dependency map. If the package is not declared in the resolved dependencies, PackageLoadError cannotFindDependencyInPackage is thrown, naming the missing package and the parent package it was requested from.","triggerScenarios":"A module URI referencing '@somePkg/...' is resolved but getDependencies() has no entry for 'somePkg' — the dependency notation's package name is absent from the project's dependency list.","commonSituations":"Importing '@foo/...' without adding foo to PklProject dependencies; forgetting `pkl project resolve`; editing dependency names/tiers; stale PklProject after adding an import; dependency declared in a different scope (local vs remote) than expected.","solutions":["Add the missing package to the dependencies section of your PklProject and run `pkl project resolve`","Run `pkl project resolve` to refresh PklProjectDependencies after dependency edits","Verify the exact package name in the import matches the declared dependency name (case-sensitive)","Check you are evaluating within the project so its dependency map is applied"],"exampleFix":"// before (PklProject)\n// import \"@myDeps/util.pkl\" but no myDeps dependency declared\n// after (PklProject)\ndependencies {\n  myDeps {\n    uri = \"package://example.com/myDeps@1.0.0\"\n  }\n}\n// then run: pkl project resolve","handlingStrategy":"validation","validationCode":"var deps = project.getDependencies(); if (!deps.containsKey(pkgName)) throw new IllegalStateException(\"package not declared in PklProject: \" + pkgName);","typeGuard":"boolean dependencyDeclared(String name, java.util.Map<String, ?> deps) { return deps.containsKey(name); }","tryCatchPattern":"try { resolved = key.resolve(securityManager); } catch (PackageLoadError e) { if (\"cannotFindDependencyInPackage\".equals(e.getErrorCode())) { throw new ProjectConfigurationException(\"Add package \" + e.getMessage() + \" to PklProject dependencies and run `pkl project resolve`\", e); } throw e; }","preventionTips":["Declare every imported package in PklProject dependencies","Run `pkl project resolve` after any dependency change","Keep import names exactly matching declared package names","Lint imports against PklProject in CI"],"tags":["java","package","dependency","pkl-project"],"backgroundTag":"missing-dependency","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}