{"record":{"id":"306c07b36378dbfc","repo":"microsoft/aspire","slug":"publishaspackagescript-requires-a-deno-package-manager-add-a","errorCode":null,"errorMessage":"PublishAsPackageScript requires a Deno package manager. Add a deno.json file or call WithDeno().","messagePattern":"PublishAsPackageScript requires a Deno package manager\\. Add a deno\\.json file or call WithDeno\\(\\)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.JavaScript/DenoHostingExtensions.cs","lineNumber":897,"sourceCode":"            DenoInspectMode.InspectWait => \"--inspect-wait\",\n            _ => \"--inspect\",\n        };\n\n        args.Add(string.IsNullOrEmpty(deno.InspectHostPort) ? flag : $\"{flag}={deno.InspectHostPort}\");\n    }\n\n    /// <summary>\n    /// Builds the container entrypoint array (<c>deno</c> plus args). Honors publish-safe command-line flags from\n    /// the explicit Deno annotation, excluding development-only watch and inspector flags.\n    /// </summary>\n    private static string[] BuildDenoEntrypoint(IResource resource, string command, string scriptPath)\n    {\n        if (resource.TryGetLastAnnotation<JavaScriptPublishModeAnnotation>(out var publishMode) &&\n            publishMode.Mode == JavaScriptPublishMode.PackageScript)\n        {\n            var packageScriptManager = resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out var packageScriptManagerAnnotation)\n                ? packageScriptManagerAnnotation\n                : throw new InvalidOperationException(\"PublishAsPackageScript requires a Deno package manager. Add a deno.json file or call WithDeno().\");\n\n            return BuildDenoPackageScriptEntrypoint(\n                packageScriptManager.ExecutableName,\n                packageScriptManager.ScriptCommand ?? \"task\",\n                publishMode.ScriptName!,\n                publishMode.RunScriptArguments);\n        }\n\n        var entrypoint = new List<string> { command };\n        var deno = resource.TryGetLastAnnotation<DenoCommandLineAnnotation>(out var denoAnnotation) ? denoAnnotation : null;\n        var runScript = resource.TryGetLastAnnotation<JavaScriptRunScriptAnnotation>(out var runScriptAnnotation) ? runScriptAnnotation : null;\n        var packageManager = resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out var packageManagerAnnotation) ? packageManagerAnnotation : null;\n        var containerScriptPath = ToDenoContainerPath(scriptPath);\n\n        if (deno is not null)\n        {\n            var serveEndpointArguments = deno.Mode == DenoCommandMode.Serve\n                ? GetDenoServeEndpointArguments(resource, isPublishMode: true, useLiteralTargetPort: true)","sourceCodeStart":879,"sourceCodeEnd":915,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.JavaScript/DenoHostingExtensions.cs#L879-L915","documentation":"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.","triggerScenarios":"Calling PublishAsPackageScript(...) on a DenoAppResource that never had WithDeno() applied and whose project directory lacks a deno.json, so GetOrAddPackageManager never created the JavaScriptPackageManagerAnnotation.","commonSituations":"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.","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."],"exampleFix":"// before\nvar deno = builder.AddDenoProject(\"api\", \"api\");\ndeno.PublishAsPackageScript(\"start\");\n// after\nvar deno = builder.AddDenoProject(\"api\", \"api\").WithDeno();\ndeno.PublishAsPackageScript(\"start\");","handlingStrategy":"validation","validationCode":"if (!resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out _)) throw new InvalidOperationException(\"Call WithDeno() before PublishAsPackageScript.\");","typeGuard":null,"tryCatchPattern":"try { app.Run(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"PublishAsPackageScript\")) { /* add WithDeno() or deno.json */ }","preventionTips":["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"],"tags":["invalid-operation-exception","deno","publish","missing-configuration"],"backgroundTag":"missing-dependency","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}