apple/pkl · error

cannotFindModuleImport

cannotFindModuleImport

Error message

cannotFindModuleImport

What it means

`cannotFindModuleImport` is thrown by ResolveDeclaredTypeNode.getImport when resolving a qualified type like `mod.SomeType`: the referenced import name is not a member of the module. The module has no member with that identifier, so the qualified type cannot be resolved.

Solutions

  1. Add or fix the import declaration for the module referenced by the qualified name
  2. Correct the import name/alias typo in the type annotation
  3. Verify the member exists on the imported module (name and spelling)

Example fix

// before
x: modu.Config
// after (with `import "config.pkl" as mod`
x: mod.Config
Defensive patterns

Strategy: validation

Validate before calling

// ensure the import alias used in qualified types is declared
if (!/^import\s+"[^"]+"\s+as\s+mod\b/m.test(source)) console.error("missing import alias 'mod'");

Prevention

When it happens

Trigger: Writing `foo.Bar` in a type position where `foo` is not an import/property of the current module; a typo in the import alias; the import was removed or renamed.

Common situations: Renaming an import alias without updating qualified type references; deleting an import statement still referenced in type annotations; referring to a module by filename instead of its import name.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/type/ResolveDeclaredTypeNode.java:52

    var curr = initialOwner;
    var next = curr.getEnclosingOwner();

    while (next != null) {
      curr = next;
      next = next.getEnclosingOwner();
    }

    assert curr.isModuleObject();
    return (VmTyped) curr;
  }

  protected VmTyped getImport(
      VmTyped module, Identifier importName, SourceSection importNameSection) {
    assert importName.isLocalProp();

    var member = module.getMember(importName);
    if (member == null) {
      throw exceptionBuilder()
          .evalError("cannotFindModuleImport", importName)
          .withSourceSection(importNameSection)
          .build();
    }

    if (!member.isImport()) {
      throw exceptionBuilder()
          .evalError("notAModuleImport", importName)
          .withSourceSection(importNameSection)
          .build();
    }

    if (member.isGlob()) {
      throw exceptionBuilder()
          .evalError("notAType", importName)
          .withSourceSection(importNameSection)
          .build();
    }

View on GitHub (pinned to f3efcbfc9b)