diff --git a/app/angular/src/server/build.ts b/app/angular/src/server/build.ts index d8abf06a4396..fe1ed4fb11e3 100644 --- a/app/angular/src/server/build.ts +++ b/app/angular/src/server/build.ts @@ -1,4 +1,13 @@ import { buildStatic } from '@storybook/core/server'; +import { logger } from '@storybook/node-logger'; import options from './options'; -buildStatic(options); +async function build() { + try { + await buildStatic(options); + } catch (error) { + logger.error(error); + } +} + +build(); diff --git a/lib/builder-webpack5/src/index.ts b/lib/builder-webpack5/src/index.ts index c1639be842c1..cec11f62cfbe 100644 --- a/lib/builder-webpack5/src/index.ts +++ b/lib/builder-webpack5/src/index.ts @@ -129,14 +129,19 @@ export const build: WebpackBuilder['build'] = async ({ options, startTime }) => const config = await getConfig(options); return new Promise((succeed, fail) => { - webpackInstance(config).run((error, stats) => { + const compiler = webpackInstance(config); + + compiler.run((error, stats) => { if (error || !stats || stats.hasErrors()) { logger.error('=> Failed to build the preview'); process.exitCode = 1; if (error) { logger.error(error.message); - return fail(error); + + compiler.close(() => fail(error)); + + return; } if (stats && (stats.hasErrors() || stats.hasWarnings())) { @@ -145,7 +150,9 @@ export const build: WebpackBuilder['build'] = async ({ options, startTime }) => errors.forEach((e) => logger.error(e.message)); warnings.forEach((e) => logger.error(e.message)); - return fail(stats); + compiler.close(() => fail(stats)); + + return; } } @@ -154,7 +161,15 @@ export const build: WebpackBuilder['build'] = async ({ options, startTime }) => stats.toJson({ warnings: true }).warnings.forEach((e) => logger.warn(e.message)); } - return succeed(stats); + // https://webpack.js.org/api/node/#run + // #15227 + compiler.close((closeErr) => { + if (closeErr) { + return fail(closeErr); + } + + return succeed(stats); + }); }); }); };