angular/angular-cli · error · Error
Could not find server output directory: ${outputPath}.
Error message
Could not find server output directory: ${outputPath}. What it means
The app-shell builder runs a server build and then looks for the compiled server output directory (server dist path joined with the locale directory) to locate the server main bundle for prerendering. If that directory does not exist on disk at the expected path, it throws. This usually means the server build output was not produced where the builder expected it.
Source
Thrown at packages/angular_devkit/build_angular/src/builders/app-shell/index.ts:148
return browserResult;
}
async function _getServerModuleBundlePath(
options: BuildWebpackAppShellSchema,
context: BuilderContext,
serverResult: ServerBuilderOutput,
browserLocaleDirectory: string,
) {
if (options.appModuleBundle) {
return path.join(context.workspaceRoot, options.appModuleBundle);
}
const { baseOutputPath = '' } = serverResult;
const outputPath = path.join(baseOutputPath, browserLocaleDirectory);
if (!fs.existsSync(outputPath)) {
throw new Error(`Could not find server output directory: ${outputPath}.`);
}
const re = /^main\.(?:[a-zA-Z0-9]{16}\.)?js$/;
const maybeMain = fs.readdirSync(outputPath).find((x) => re.test(x));
if (!maybeMain) {
throw new Error('Could not find the main bundle.');
}
return path.join(outputPath, maybeMain);
}
async function _appShellBuilder(
options: BuildWebpackAppShellSchema,
context: BuilderContext,
): Promise<BuilderOutput> {
context.logger.warn(
'The "@angular-devkit/build-angular:app-shell" builder is deprecated as part of Angular\'s Webpack support deprecation. ' +View on GitHub (pinned to bb72145f9a)
Solutions
- Verify the server target (serverTarget option) actually builds and note its outputPath (run it standalone: ng run app:server).
- Align the server target's outputPath in angular.json so the server main.js lands where app-shell expects (or set serverTarget output paths explicitly).
- Check whether localization/locale directory config causes the outputPath to include a locale subfolder that does not exist; adjust locales or output structure.
- Clean dist output and rerun so no stale build result points at deleted directories.
Example fix
// before (angular.json, server target)
"options": { "outputPath": "dist/my-app/server-custom" }
// after
"options": { "outputPath": "dist/my-app/server" } Defensive patterns
Strategy: validation
Validate before calling
import * as fs from 'fs';
import * as path from 'path';
const serverOut = path.join(serverBaseOutputPath, browserLocaleDirectory);
if (!fs.existsSync(serverOut)) {
throw new Error(`Server output missing before app-shell run: ${serverOut}`);
} Try / catch
try {
await runAppShell();
} catch (e) {
if (String(e.message).includes('Could not find server output directory')) {
// rebuild server target / fix outputPath before retrying
}
throw e;
} Prevention
- Keep the server target outputPath aligned with what app-shell computes
- Run the server target standalone to verify output before app-shell
- Avoid manually deleting dist folders referenced by build results
- Pin output paths explicitly in angular.json instead of defaults
When it happens
Trigger: Running the app-shell builder where the server target builds to a different outputPath/baseOutputPath than expected, the server build succeeded but wrote nothing (wrong outputPath in server architect target config), a custom browserLocaleDirectory was injected but the built output has no such subdirectory, or the server build output was deleted between build and lookup.
Common situations: Customizing serverTarget output path in angular.json and forgetting to align it; monorepo setups where outputs are redirected (e.g. to a shared dist root) so the computed joined path is wrong; localization configurations creating unexpected locale subfolders; running with a cached/stale build result object.
Related errors
- Could not find the main bundle.
- Unknown file requested: ${requestedPath}
- Configuration error: found 'withAppShell()' without 'withRou
- Error(s) occurred while extracting routes:\n${errors.map((er
- Package "${packageName}" has an invalid builders manifest pa
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/17252556efaf469b.
Report an issue: GitHub.