microsoft/aspire · error · InvalidOperationException
WithBuildScript requires a Deno package manager. Add a…
Error message
WithBuildScript requires a Deno package manager. Add a deno.json file or call WithDeno().
What it means
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.
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.
Example fix
// before
builder.AddJavaScriptApp("svc", "main.ts").WithBuildScript("compile");
// after
builder.AddJavaScriptApp("svc", "main.ts").WithDeno().WithBuildScript("compile"); Defensive patterns
Strategy: validation
Validate before calling
// ensure a package manager is configured before WithBuildScript
if (!resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out _))
{
resource.WithDeno(); // or add a deno.json to the app directory
} Try / catch
try
{
app.WithDeno().WithBuildScript("compile");
}
catch (InvalidOperationException ex) when (ex.Message.Contains("WithBuildScript requires a Deno package manager"))
{
// configure Deno package management before the build script
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- Deno command-line options configured with the WithDeno*…
- Generated Deno Dockerfiles do not support alternate package…
- PublishAsPackageScript requires a Deno package manager. Add…
- ASPIRERADIUS068
- Capability host ' ' on project ' ' requires a CosmosDB…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/6d88858cc94f30f2.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs:964
var denoCacheCommand = BuildDenoCacheCommand(dockerfileContext.Resource, scriptPath, resource.WorkingDirectory);
buildStage
.EmptyLine()
// Pin DENO_DIR to a deterministic path so the runtime stage can copy the cache
// regardless of the base image's own default. The official denoland/deno image
// already uses /deno-dir, but a custom build image (WithDockerfileBaseImage) may not.
.Env("DENO_DIR", "/deno-dir")
.EmptyLine()
.WorkDir("/app")
.Copy(".", ".")
.EmptyLine()
.Run(denoCacheCommand);
}
if (dockerfileContext.Resource.TryGetLastAnnotation<JavaScriptBuildScriptAnnotation>(out var buildCommand))
{
if (!dockerfileContext.Resource.TryGetLastAnnotation<JavaScriptPackageManagerAnnotation>(out var packageManager))
{
throw new InvalidOperationException("WithBuildScript requires a Deno package manager. Add a deno.json file or call WithDeno().");
}
buildStage
.EmptyLine()
.Run(BuildPackageScriptCommand(packageManager, buildCommand));
}
var logger = dockerfileContext.Services.GetService<ILogger<JavaScriptAppResource>>();
dockerfileContext.Builder.AddContainerFilesStages(dockerfileContext.Resource, logger);
var hasCustomRuntimeImage = baseImageAnnotation?.RuntimeImage is not null;
var baseRuntimeImage = baseImageAnnotation?.RuntimeImage ?? DefaultDenoImage;
var runtimeStage = dockerfileContext.Builder
.From(baseRuntimeImage, "runtime")
.EmptyLine()
// Match the build stage's DENO_DIR so the copied cache is discovered at runtime.
.Env("DENO_DIR", "/deno-dir")
.EmptyLine()View on GitHub (pinned to 25830f84bd)