apple/pkl · error · PackageLoadError

cannotFindDependencyInPackage

cannotFindDependencyInPackage

Error message

cannotFindDependencyInPackage

What it means

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.

Solutions

  1. Add the missing package to the dependencies section of your PklProject and run `pkl project resolve`
  2. Run `pkl project resolve` to refresh PklProjectDependencies after dependency edits
  3. Verify the exact package name in the import matches the declared dependency name (case-sensitive)
  4. Check you are evaluating within the project so its dependency map is applied

Example fix

// before (PklProject)
// import "@myDeps/util.pkl" but no myDeps dependency declared
// after (PklProject)
dependencies {
  myDeps {
    uri = "package://example.com/myDeps@1.0.0"
  }
}
// then run: pkl project resolve
Defensive patterns

Strategy: validation

Validate before calling

var deps = project.getDependencies(); if (!deps.containsKey(pkgName)) throw new IllegalStateException("package not declared in PklProject: " + pkgName);

Type guard

boolean dependencyDeclared(String name, java.util.Map<String, ?> deps) { return deps.containsKey(name); }

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/a118926d215239cf. Report an issue: GitHub.

Appendix: source

Thrown at pkl-core/src/main/java/org/pkl/core/module/ModuleKeys.java:633

    }

    @Override
    public URI getUri() {
      return packageAssetUri.getUri();
    }

    @Override
    public URI resolveUri(URI baseUri, URI importUri) throws IOException, SecurityManagerException {
      var ssp = importUri.getSchemeSpecificPart();
      if (importUri.isAbsolute() || !ssp.startsWith("@")) {
        return ModuleKey.super.resolveUri(baseUri, importUri);
      }
      var parsed = IoUtils.parseDependencyNotation(ssp);
      var name = parsed.getFirst();
      var path = parsed.getSecond();
      var dependency = getDependencies().get(name);
      if (dependency == null) {
        throw new PackageLoadError(
            "cannotFindDependencyInPackage",
            name,
            packageAssetUri.getPackageUri().getDisplayName());
      }
      return dependency.getPackageUri().toPackageAssetUri(path).getUri();
    }
  }

  /** Represents a module imported via the {@code package} scheme. */
  private static class Package extends AbstractPackage {

    Package(PackageAssetUri packageAssetUri) {
      super(packageAssetUri);
    }

    private PackageResolver getPackageResolver() {
      var packageResolver = VmContext.get(null).getPackageResolver();
      assert packageResolver != null;

View on GitHub (pinned to f3efcbfc9b)