apple/pkl · error · VmException
cannotFindModule
cannotFindModule
Error message
cannotFindModule
What it means
A module referenced by an import/glob expansion could not be found: the resolver threw FileNotFoundException/NoSuchFileException, converted to cannotFindModule with the entry's string value and source section.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java:132
var moduleUri = globElement.uri();
var mk = moduleResolver.resolve(moduleUri);
var rmk = mk.resolve(securityManager);
result.add(new ImportEntry(moduleUri, rmk));
}
} else {
var resolvedUri =
IoUtils.resolve(securityManager, moduleKey, IoUtils.toUri(entry.stringValue()));
var mKey = moduleResolver.resolve(resolvedUri);
var rmk = mKey.resolve(securityManager);
result.add(new ImportEntry(resolvedUri, rmk));
}
} catch (InvalidGlobPatternException e) {
throw new VmExceptionBuilder()
.evalError("invalidGlobPattern", entry.stringValue())
.withSourceSection(entry.sourceSection())
.build();
} catch (FileNotFoundException | NoSuchFileException e) {
throw new VmExceptionBuilder()
.evalError("cannotFindModule", entry.stringValue())
.withSourceSection(entry.sourceSection())
.build();
} catch (URISyntaxException e) {
throw new VmExceptionBuilder()
.evalError("invalidModuleUri", entry.stringValue())
.withHint(e.getReason())
.withSourceSection(entry.sourceSection())
.build();
} catch (IOException e) {
throw new VmExceptionBuilder()
.evalError("ioErrorLoadingModule", entry.stringValue())
.withCause(e)
.withSourceSection(entry.sourceSection())
.build();
} catch (SecurityManagerException | PackageLoadError e) {
throw new VmExceptionBuilder()
.withSourceSection(entry.sourceSection())View on GitHub (pinned to f3efcbfc9b)
Solutions
- Check the path/URI spelling at the reported source section
- Ensure the referenced module exists relative to the importing module or via the correct scheme (project:, package:, file:, etc.)
- Fetch/sync package dependencies (pkl project resolve) if it comes from a dependency
Example fix
// before
import("confg.pkl")
// after
import("config.pkl") Defensive patterns
Strategy: validation
Validate before calling
for (const dep of imports) { if (!fs.existsSync(resolve(importerDir, dep))) throw new Error('missing module: ' + dep) } Prevention
- Verify import paths relative to the importing module
- Run `pkl project resolve` for package dependencies
- Keep module files in place; rename with search/replace
When it happens
Trigger: import("missing/file.pkl") or a glob that resolves to paths deleted before reading; classpath/path missing during collectImports.
Common situations: Typo in the module path; file moved/renamed; running from a different working directory; package dependency not fetched.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- ioErrorLoadingModule
- ioErrorResolvingGlob
- resourcePastRootDir|modulePastRootDir
- Is a directory
- cannotFindStdLibModule
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/c6c00ce4d85aa367.
Report an issue: GitHub.