{"record":{"id":"6d88858cc94f30f2","repo":"microsoft/aspire","slug":"withbuildscript-requires-a-deno-package-manager-add-a-deno","errorCode":null,"errorMessage":"WithBuildScript requires a Deno package manager. Add a deno.json file or call WithDeno().","messagePattern":"WithBuildScript 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/JavaScriptHostingExtensions.cs","lineNumber":964,"sourceCode":"                        var denoCacheCommand = BuildDenoCacheCommand(dockerfileContext.Resource, scriptPath, resource.WorkingDirectory);\n                        buildStage\n                            .EmptyLine()\n                            // Pin DENO_DIR to a deterministic path so the runtime stage can copy the cache\n                            // regardless of the base image's own default. The official denoland/deno image\n                            // already uses /deno-dir, but a custom build image (WithDockerfileBaseImage) may not.\n                            .Env(\"DENO_DIR\", \"/deno-dir\")\n                            .EmptyLine()\n                            .WorkDir(\"/app\")\n                            .Copy(\".\", \".\")\n                            .EmptyLine()\n                            .Run(denoCacheCommand);\n                    }\n\n                    if (dockerfileContext.Resource.TryGetLastAnnotation<JavaScriptBuildScriptAnnotation>(out var buildCommand))\n                    {\n                        if (!dockerfileContext.Resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out var packageManager))\n                        {\n                            throw new InvalidOperationException(\"WithBuildScript requires a Deno package manager. Add a deno.json file or call WithDeno().\");\n                        }\n\n                        buildStage\n                            .EmptyLine()\n                            .Run(BuildPackageScriptCommand(packageManager, buildCommand));\n                    }\n\n                    var logger = dockerfileContext.Services.GetService<ILogger<JavaScriptAppResource>>();\n                    dockerfileContext.Builder.AddContainerFilesStages(dockerfileContext.Resource, logger);\n\n                    var hasCustomRuntimeImage = baseImageAnnotation?.RuntimeImage is not null;\n                    var baseRuntimeImage = baseImageAnnotation?.RuntimeImage ?? DefaultDenoImage;\n                    var runtimeStage = dockerfileContext.Builder\n                        .From(baseRuntimeImage, \"runtime\")\n                            .EmptyLine()\n                            // Match the build stage's DENO_DIR so the copied cache is discovered at runtime.\n                            .Env(\"DENO_DIR\", \"/deno-dir\")\n                            .EmptyLine()","sourceCodeStart":946,"sourceCodeEnd":982,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L946-L982","documentation":"WithBuildScript emits a `deno task build`-style RUN step into the generated Dockerfile, which requires a package-manager annotation. During Dockerfile generation in AddDenoApp, if the resource has a JavaScriptBuildScriptAnnotation but no JavaScriptPackageManagerAnnotation, the library cannot build the command and throws.","triggerScenarios":"Calling WithBuildScript(\"...\") on a Deno/JavaScript app that lacks a package manager configuration — no deno.json detected and no WithDeno() called — then generating the Dockerfile.","commonSituations":"A Deno project without deno.json; adding WithBuildScript copied from an npm sample without the equivalent npm setup; build-script helper applied conditionally and package-manager detection skipped.","solutions":["Call WithDeno() on the resource so the Deno package manager annotation is set.","Add a deno.json file to the app directory so package management is detected.","Remove WithBuildScript if no build step is actually needed for the container image."],"exampleFix":"// before\nbuilder.AddJavaScriptApp(\"svc\", \"main.ts\").WithBuildScript(\"compile\");\n// after\nbuilder.AddJavaScriptApp(\"svc\", \"main.ts\").WithDeno().WithBuildScript(\"compile\");","handlingStrategy":"validation","validationCode":"// ensure a package manager is configured before WithBuildScript\nif (!resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out _))\n{\n    resource.WithDeno(); // or add a deno.json to the app directory\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    app.WithDeno().WithBuildScript(\"compile\");\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"WithBuildScript requires a Deno package manager\"))\n{\n    // configure Deno package management before the build script\n}","preventionTips":["Configure the package manager (WithDeno or deno.json) before adding build scripts.","Do not copy WithBuildScript usage from npm examples onto unconfigured Deno resources.","Confirm the app directory has deno.json when relying on auto-detection."],"tags":["deno","build-script","package-manager","missing-dependency"],"backgroundTag":"missing-dependency","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}