microsoft/aspire · error · InvalidOperationException
PublishAsPackageScript requires a Deno package manager. Add…
Error message
PublishAsPackageScript requires a Deno package manager. Add a deno.json file or call WithDeno().
What it means
PublishAsPackageScript (JavaScriptPublishMode.PackageScript) for a Deno app depends on package-manager and install-command annotations that only exist when Deno package management is configured. During Dockerfile generation in AddDenoApp, if those annotations are missing, the library cannot emit the package-script build stage and throws.
Solutions
- Add a deno.json file to the application directory so the Deno package manager is detected.
- Call WithDeno() on the resource to configure Deno package management explicitly.
- Remove PublishAsPackageScript() if the resource is not actually a Deno package-script app.
Example fix
// before
builder.AddJavaScriptApp("pkg", "main.ts").PublishAsPackageScript();
// after
builder.AddJavaScriptApp("pkg", "main.ts").WithDeno().PublishAsPackageScript(); Defensive patterns
Strategy: validation
Validate before calling
// ensure Deno package management exists before PublishAsPackageScript
if (!resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out _) ||
!resource.TryGetLastAnnotation<JavaScriptInstallCommandAnnotation>(out _))
{
resource.WithDeno(); // or ensure a deno.json exists in the app directory
} Try / catch
try
{
app.WithDeno().PublishAsPackageScript();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("PublishAsPackageScript requires a Deno package manager"))
{
// add deno.json or call WithDeno() first
} Prevention
- Always create a deno.json in Deno projects so package management is detectable.
- Chain WithDeno() before PublishAsPackageScript() as a habit.
- Verify package-manager detection succeeded when using conditional resource setup.
When it happens
Trigger: Calling PublishAsPackageScript() on a JavaScript/Deno app resource that has no deno.json (so no Deno package manager annotation is inferred) and no explicit WithDeno() call, then generating its Dockerfile.
Common situations: A Deno project without a deno.json file relying on defaults; forgetting WithDeno() after applying PublishAsPackageScript; a resource where package-manager detection failed silently.
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
- Generated Deno Dockerfiles do not support
- PublishAsPackageScript requires a Deno package manager. Add…
- WithBuildScript requires a Deno package manager. Add a…
- A ConfigureRadiusInfrastructure callback changed port
- A ConfigureRadiusInfrastructure callback left container
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/19d9bceacb309c84.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs:927
// Deno ships its own runtime, so both stages default to the same Deno image. Unlike the Bun
// variant there is no separate production-dependency install stage: Deno caches remote and
// npm dependencies under DENO_DIR. Direct run/serve entrypoints pre-populate that cache in
// the build stage and use --cached-only at runtime. Task entrypoints are opaque shell
// commands in deno.json, so Aspire cannot safely infer their module graph.
var baseBuildImage = baseImageAnnotation?.BuildImage ?? DefaultDenoImage;
var buildStage = dockerfileContext.Builder
.From(baseBuildImage, "build");
// Package-script builds install from the manifest layer before copying the remaining source.
// Direct run/serve builds copy the full module graph first, then cache it with the same
// resolution and lock flags used by the runtime entrypoint.
dockerfileContext.Resource.TryGetLastAnnotation<JavaScriptPublishModeAnnotation>(out var publishMode);
if (publishMode?.Mode == JavaScriptPublishMode.PackageScript)
{
if (!dockerfileContext.Resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out var packageManager) ||
!dockerfileContext.Resource.TryGetLastAnnotation<JavaScriptInstallCommandAnnotation>(out var installCommand))
{
throw new InvalidOperationException("PublishAsPackageScript requires a Deno package manager. Add a deno.json file or call WithDeno().");
}
buildStage.EmptyLine();
packageManager.InitializeDockerBuildStage?.Invoke(buildStage);
buildStage
.EmptyLine()
.WorkDir("/app");
var copiedAllSource = buildStage.CopyPackageFilesForInstall(packageManager);
buildStage.AddInstallCommand(packageManager, installCommand);
if (!copiedAllSource)
{
buildStage.Copy(".", ".");
}
}
else
{View on GitHub (pinned to 25830f84bd)