microsoft / microsoft/aspire

Auto-generated Dockerfiles break yarn/npm workspaces monorepos

Open
#15,877 3 comments 1 reaction 0 assignees View on GitHub
aspirifridays javascript
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

## Description

When using `publishAsDockerFile` (or the auto-generated Dockerfile for JavaScript apps), Aspire copies only the app's subfolder into the Docker image. This breaks monorepos using yarn workspaces (or npm workspaces) because:

1. **Hoisted dependencies** — `node_modules` are hoisted to the repo root by the workspace manager, so the app subfolder alone is missing most dependencies
2. **Cross-directory imports** — Apps commonly import from sibling packages (e.g., `../packages/`, `../scripts/`) which aren't included
3. **Root config files** — `.env` files, root `package.json`, `yarn.lock` etc. are not copied

This results in build failures like `cross-env: not found` (exit code 127) or `Could not resolve '../scripts/...'` during the Docker build.

## Expected behavior

Aspire should detect workspace configurations (`workspaces` field in root `package.json`, or `pnpm-workspace.yaml`) and use the workspace root as the Docker build context, copying all necessary workspace packages.

Alternatively, provide clear documentation and examples for monorepo setups, or allow the user to easily specify the build context.

## Workaround

Use `publishAsDockerFileWithConfigure` to point at a custom Dockerfile that uses the repo root as build context:

\\\ ypescript
app.publishAsDockerFileWithConfigure(async (container) => {
await container.withDockerfile("../", { dockerfilePath: "Dockerfile.aspire" });
});
\\\

## Environment

- Aspire SDK: 13.2.1 (TypeScript)
- Package manager: Yarn 1.x with workspaces

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.