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
BuildDenoEntrypoint supports a PackageScript publish mode (running a task from deno.json via 'deno task'), which requires a package-manager annotation naming the Deno executable. When PublishAsPackageScript was applied but no Deno package manager annotation exists (no deno.json detected and WithDeno() not called), the library throws InvalidOperationException explaining how to fix it.
Solutions
- Call WithDeno() on the resource builder before/alongside PublishAsPackageScript.
- Ensure a deno.json (or deno.jsonc) exists at the resource root so the Deno package manager is auto-detected.
- Verify the resource directory configured in AddDenoProject/AddDeno actually contains deno.json.
- Remove PublishAsPackageScript if you intend plain 'deno run' publishing instead.
Example fix
// before
var deno = builder.AddDenoProject("api", "api");
deno.PublishAsPackageScript("start");
// after
var deno = builder.AddDenoProject("api", "api").WithDeno();
deno.PublishAsPackageScript("start"); Defensive patterns
Strategy: validation
Validate before calling
if (!resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out _)) throw new InvalidOperationException("Call WithDeno() before PublishAsPackageScript."); Try / catch
try { app.Run(); } catch (InvalidOperationException ex) when (ex.Message.Contains("PublishAsPackageScript")) { /* add WithDeno() or deno.json */ } Prevention
- Always call WithDeno() on Deno resources that use Deno-specific publish modes
- Keep deno.json present and named exactly 'deno.json' at the project root
- Chain builder calls in one fluent statement so ordering is explicit
When it happens
Trigger: Calling PublishAsPackageScript(...) on a DenoAppResource that never had WithDeno() applied and whose project directory lacks a deno.json, so GetOrAddPackageManager never created the JavaScriptPackageManagerAnnotation.
Common situations: Applying a generic JavaScript publish-mode snippet to a Deno resource without the WithDeno() call; renamed/missing deno.json so auto-detection fails; ordering issues where PublishAsPackageScript runs before WithDeno in a conditional build path.
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
- ClusterIssuer ' ' has no spec. Configure it with…
- Generated Deno Dockerfiles do not support
- PublishAsPackageScript requires a Deno package manager. Add…
- The argument ' ' cannot be configured with…
- Unsupported Deno node_modules mode
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/306c07b36378dbfc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.JavaScript/DenoHostingExtensions.cs:897
DenoInspectMode.InspectWait => "--inspect-wait",
_ => "--inspect",
};
args.Add(string.IsNullOrEmpty(deno.InspectHostPort) ? flag : $"{flag}={deno.InspectHostPort}");
}
/// <summary>
/// Builds the container entrypoint array (<c>deno</c> plus args). Honors publish-safe command-line flags from
/// the explicit Deno annotation, excluding development-only watch and inspector flags.
/// </summary>
private static string[] BuildDenoEntrypoint(IResource resource, string command, string scriptPath)
{
if (resource.TryGetLastAnnotation<JavaScriptPublishModeAnnotation>(out var publishMode) &&
publishMode.Mode == JavaScriptPublishMode.PackageScript)
{
var packageScriptManager = resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out var packageScriptManagerAnnotation)
? packageScriptManagerAnnotation
: throw new InvalidOperationException("PublishAsPackageScript requires a Deno package manager. Add a deno.json file or call WithDeno().");
return BuildDenoPackageScriptEntrypoint(
packageScriptManager.ExecutableName,
packageScriptManager.ScriptCommand ?? "task",
publishMode.ScriptName!,
publishMode.RunScriptArguments);
}
var entrypoint = new List<string> { command };
var deno = resource.TryGetLastAnnotation<DenoCommandLineAnnotation>(out var denoAnnotation) ? denoAnnotation : null;
var runScript = resource.TryGetLastAnnotation<JavaScriptRunScriptAnnotation>(out var runScriptAnnotation) ? runScriptAnnotation : null;
var packageManager = resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out var packageManagerAnnotation) ? packageManagerAnnotation : null;
var containerScriptPath = ToDenoContainerPath(scriptPath);
if (deno is not null)
{
var serveEndpointArguments = deno.Mode == DenoCommandMode.Serve
? GetDenoServeEndpointArguments(resource, isPublishMode: true, useLiteralTargetPort: true)View on GitHub (pinned to 25830f84bd)