apple/pkl · error · VmException
invalidModuleUri
invalidModuleUri
Error message
invalidModuleUri
What it means
Sentinel evalError 'invalidModuleUri' raised by VmImportAnalyzer.collectImports: a module import URI collected during analyzer traversal could not be resolved through IoUtils.resolve/moduleResolver, i.e. an import statement in the analyzed module refers to a malformed or unresolvable URI.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java:137
} 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())
.withCause(e)
.build();
} catch (ExternalReaderProcessException e) {
throw new VmExceptionBuilder()
.withSourceSection(entry.sourceSection())View on GitHub (pinned to f3efcbfc9b)
Solutions
- Fix the import URI in the Pkl source to be a valid absolute or resolvable relative URI.
- Check for typos or unsupported schemes in the import path.
Example fix
// before
import("my modules/a.pkl")
// after
import("my%20modules/a.pkl") Defensive patterns
Strategy: validation
Validate before calling
function assertValidUri(u) { try { new URL(u) } catch (e) { throw new Error('invalid module URI: ' + u + ' (' + e.message + ')') } } Type guard
const isValidUri = (u) => { try { new URL(u); return true } catch { return false } }; Prevention
- Percent-encode spaces and special characters in URIs
- Prefer relative paths for local modules
- Validate dynamically built import strings
When it happens
Trigger: import("htp:/bad uri.pkl") or other malformed URIs (illegal characters, spaces, bad scheme syntax) during collectImports.
Common situations: Spaces or unencoded special characters in paths; missing scheme; accidentally interpolating an invalid value into the import string.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- invalidModuleUri
- cannotHaveRelativeImport
- cannotGlobUri
- invalidModuleUri
- Failed to convert `pkl.base#String` to `java.net.URI`.
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/5d7cb992da3eefd3.
Report an issue: GitHub.