angular/angular-cli · error · Error
Compilation output path cannot be empty.
Error message
Compilation output path cannot be empty.
What it means
The ServiceWorkerPlugin's apply() augments the built app with a service worker after compilation. It reads the output path from compilation.outputOptions.path (not build options) because localization may redirect output to a temp directory. If that path is empty/undefined, the plugin cannot locate the output to augment, so it throws.
Source
Thrown at packages/angular_devkit/build_angular/src/tools/webpack/plugins/service-worker-plugin.ts:38
constructor(private readonly options: ServiceWorkerPluginOptions) {}
apply(compiler: Compiler) {
compiler.hooks.done.tapPromise('angular-service-worker', async (stats) => {
if (stats.hasErrors()) {
// Don't generate a service worker if the compilation has errors.
// When there are errors some files will not be emitted which would cause other errors down the line such as readdir failures.
return;
}
const { projectRoot, root, baseHref = '', ngswConfigPath } = this.options;
const { compilation } = stats;
// We use the output path from the compilation instead of build options since during
// localization the output path is modified to a temp directory.
// See: https://github.com/angular/angular-cli/blob/7e64b1537d54fadb650559214fbb12707324cd75/packages/angular_devkit/build_angular/src/utils/i18n-options.ts#L251-L252
const outputPath = compilation.outputOptions.path;
if (!outputPath) {
throw new Error('Compilation output path cannot be empty.');
}
try {
await augmentAppWithServiceWorker(
projectRoot,
root,
outputPath,
baseHref,
ngswConfigPath,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(compiler.inputFileSystem as any).promises,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(compiler.outputFileSystem as any).promises,
);
} catch (error) {
compilation.errors.push(
new compilation.compiler.webpack.WebpackError(
`Failed to generate service worker - ${error instanceof Error ? error.message : error}`,View on GitHub (pinned to bb72145f9a)
Solutions
- Ensure `outputPath` in your build options is set and non-empty.
- Remove any custom webpack configuration that overrides or empties `output.path`.
- Disable the service worker (`serviceWorker: false` or remove ngswConfigPath) if building in an environment without a real output path (e.g. dev-server).
- Upgrade Angular CLI; later versions handle dev-server/service-worker combinations differently.
Example fix
// before (angular.json)
"options": { "serviceWorker": true, "ngswConfigPath": "ngsw-config.json" }
// after (when using dev-server / no outputPath)
"configurations": { "development": { "serviceWorker": false } } Defensive patterns
Strategy: validation
Validate before calling
const outputPath = compilation.outputOptions.path;
if (!outputPath) throw new Error('Cannot enable service worker: compilation output path is empty.'); Type guard
function hasOutputPath(o: webpack.Compilation['outputOptions']): o is typeof o & { path: string } {
return typeof o.path === 'string' && o.path.length > 0;
} Try / catch
try {
await runBuild();
} catch (err) {
if (err instanceof Error && err.message === 'Compilation output path cannot be empty.') {
logger.error('Service worker enabled but no output path set; check outputPath/output.path in your config.');
} else throw err;
} Prevention
- Always set outputPath in angular.json when serviceWorker is enabled.
- Never override webpack output.path to empty in custom webpack configs.
- Disable serviceWorker in dev-server/development configurations.
- Keep the CLI version matched with your webpack version.
When it happens
Trigger: Running a build with service worker enabled (ngswConfigPath set) while the webpack compilation's outputOptions.path is empty — e.g. an misconfigured output path, dev-server in-memory output without a path, or a custom webpack config overriding output.
Common situations: Custom webpack configs that clear/override `output.path`; running via dev-server with service worker enabled where output is memory-only; programmatic use of the builder without a valid output path; localization builds where the temp output path setup failed.
Related errors
- Webpack Dev Server configuration was not set.
- No options were specified to "postcss-cli-resources".
- Invalid Webpack stats configuration.
- Multiple bundles have been named the same: '${duplicates.joi
- Webpack configuration file ${configPath} does not exist.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/7d96029eb498746e.
Report an issue: GitHub.