Ce contenu n’est pas encore disponible dans votre langue.
When you create a TypeScript AppHost with aspire new, the CLI scaffolds a project with the following structure:
Répertoiremy-apphost/
Répertoire.aspire/modules/ Generated TypeScript SDK (do not edit)
aspire.mts
base.mts
transport.mts
apphost.mts Your AppHost entry point
aspire.config.json Aspire configuration
package.json
tsconfig.apphost.json
When you run aspire init --language typescript in an existing JavaScript or TypeScript app that already has a root package.json, Aspire creates the AppHost in a nested aspire-apphost/ package. The root aspire.config.json points to aspire-apphost/apphost.mts, and the root package.json gets Aspire delegate scripts so the existing app package keeps its own module and toolchain settings:
Répertoiremy-existing-app/
Répertoireaspire-apphost/
Répertoire.aspire/modules/ Generated TypeScript SDK (do not edit)
aspire.mts
base.mts
transport.mts
apphost.mts Your AppHost entry point
package.json
tsconfig.apphost.json
aspire.config.json Aspire configuration
package.json Existing app package with Aspire delegate scripts
Use aspire add from the AppHost root to add hosting integrations. The CLI adds the package to the packages section, restores AppHost dependencies, and regenerates the TypeScript SDK in .aspire/modules/:
Add an integration
aspireaddredis
This updates aspire.config.json so the package is restored the next time the AppHost runs:
aspire.config.json
{
"packages":{
"Aspire.Hosting.JavaScript":"13.3.0",
"Aspire.Hosting.Redis":"13.3.0"
}
}
Run aspire restore when you want to regenerate .aspire/modules/ without starting the AppHost, such as after switching branches, updating package versions, or preparing a CI job:
The .aspire/modules/ directory under the AppHost root contains the generated TypeScript SDK. It’s created and updated automatically by the Aspire CLI — do not edit these files.
File
Purpose
aspire.mts
Generated typed API for all your installed integrations
base.mts
Base types and handle infrastructure
transport.mts
JSON-RPC transport layer
The SDK regenerates when:
You run aspire add to add or update an integration
You run aspire run or aspire start and the package list has changed
The Aspire CLI supports the following package managers at the AppHost root — the directory that contains your apphost.mts and aspire.config.json. The CLI selects between them by inspecting package manager signals, including the packageManager field in package.json, lock files, and package manager configuration in the AppHost root.
Package manager
Detection signals
Version expectation
npm
packageManager, package-lock.json, or no other signal
npm 10 or later; npm is the default
pnpm
packageManager or pnpm-lock.yaml
pnpm 10 or later
Yarn
packageManager, yarn.lock, .yarnrc.yml, or .yarn/
Yarn 4 or later (Berry)
Bun
packageManager, bun.lock, or bun.lockb
Bun 1.2 or later
Yarn Classic (v1)
yarn.lock with # yarn lockfile v1 or packageManager with [email protected]
Not supported
This policy governs the AppHost root only. Apps the AppHost orchestrates — for example, a Node.js service added with addNodeApp, a Bun guest app, or a workspace package — can use any package manager their own tooling requires; they are independent of the AppHost-root toolchain.
Aspire end-to-end tests cover TypeScript AppHosts with representative packageManager pins such as [email protected], [email protected], [email protected], and [email protected]. These tested versions are representative points within the supported ranges, not the only versions you can use.
TypeScript AppHosts target the Node.js engine range that aspire init writes into the scaffolded AppHost package.json:
package.json — supported engines.node
{
"engines":{
"node":"^20.19.0 || ^22.13.0 || >=24"
}
}
The supported ranges are:
Node.js 20.19+ — supported.
Node.js 22.13+ (22.x LTS) — supported.
Node.js 24.x and later — supported by the scaffolded engines.node constraint.
Older Node.js versions are not supported. Package managers may enforce engines.node on install (for example, pnpm does by default, while npm only does when engine-strict is configured), so unsupported runtimes are best treated as blocked even when a given toolchain only warns.
The Aspire CLI automatically detects which Node-compatible package manager your project uses and adjusts install and run commands accordingly. The following toolchains are supported: npm (default), Bun, Yarn, and pnpm.
Detection follows the supported AppHost-root package managers policy. The CLI resolves the toolchain by inspecting the AppHost directory and its parent directories (up to eight levels). It checks, in order:
The packageManager field in package.json — for example, "packageManager": "[email protected]".
Lockfiles: bun.lock or bun.lockb → Bun; pnpm-lock.yaml → pnpm; yarn.lock, .yarnrc.yml, or a .yarn/ directory → Yarn.
If nothing is found, npm is used as the default.
The search walks up parent directories, so a workspace-level packageManager setting or lockfile is picked up automatically by nested AppHosts.
The recommended way to pin the toolchain is with the packageManager field in package.json, which Aspire uses for toolchain detection. This field is also used by Node.js Corepack for package managers such as Yarn and pnpm:
The aspire doctor command checks that the required JavaScript toolchain executable is available. If Bun, Yarn, or pnpm is detected but not installed, the command reports an error with install guidance.
TypeScript AppHosts support fluent chaining for builder methods — for example, builder.addContainer(...).withReference(...) — so you can build resource graphs in a compact, readable style. Starting with Aspire 13.4, the generated SDK extends this to all generated async methods that return a chainable wrapper type: environment helpers, execution-context queries, and endpoint property accessors.
Previously, using these methods required splitting the chain or using a double await:
apphost.ts (before)
// Two separate awaits were needed when chaining through async wrapper-returning methods
Before starting a TypeScript AppHost, the Aspire CLI runs tsc --noEmit to check for type errors to prevent the dashboard and resources from starting in a partially broken state. If your AppHost has TypeScript compile errors, aspire run and aspire publish stop before the AppHost launches and display the diagnostic output:
apphost.mts(22,7): error TS2322: Type 'string' is not assignable to type 'number'.
When you use aspire run in watch mode, the TypeScript validation is embedded in the nodemon restart command. The watcher can still start even if there are initial type errors — it will recover automatically as you edit and save files that fix the errors.
When you run a TypeScript AppHost with an HTTPS launch profile, the Aspire CLI
needs a trusted HTTPS development certificate to be present on your machine.
Unlike .NET AppHost users who typically have the .NET SDK on their PATH, TypeScript
AppHost users may not have dotnet available, so the Aspire CLI provides its own
certificate management commands.
If you see an error similar to the following when running aspire run:
Unable to configure HTTPS endpoint. No server certificate was specified, and the default
developer certificate could not be found or is out of date. To generate and trust a
developer certificate run 'aspire certs trust'. For more information on configuring
HTTPS see https://aspire.dev/docs/.
Run the following command to create and trust the development certificate:
Aspire CLI
aspirecertstrust
See Certificate configuration for details
on HTTPS certificate management in Aspire, including Linux-specific setup.
When the Aspire CLI runs a TypeScript (Node.js) AppHost, it contacts a managed server to generate the TypeScript SDK. That server loads NuGet-restored packages (Aspire.Hosting.JavaScript, Aspire.TypeSystem, and related assemblies). If the CLI version and the SDK version in aspire.config.json differ in major, minor, patch, or prerelease identifiers (excluding build metadata), code generation can fail.
Before starting the AppHost, the CLI compares its built-in SDK version against the sdk.version value in aspire.config.json. When the two differ, the CLI prints a warning:
⚠ The installed Aspire CLI version (<CLI_VERSION>) differs from the configured
Aspire SDK version (<SDK_VERSION>). If you run into errors, run 'aspire update'
to align them.
The AppHost still starts after the warning. If codegen succeeds, no further action is required. If codegen fails, run aspire update to realign the CLI and SDK to the same version.
Run aspire update to update the packages in aspire.config.json to match the installed CLI version, or reinstall the CLI to match the SDK version already in use: