diff --git a/packages/metro/src/index.js b/packages/metro/src/index.js index 037631fd..4d4a6db1 100644 --- a/packages/metro/src/index.js +++ b/packages/metro/src/index.js @@ -320,7 +320,13 @@ exports.runBuild = async (options: RunBuildOptions) => { options.onBegin(); } - const metroBundle = await output.build(metroServer, requestOptions); + let metroBundle; + + try { + metroBundle = await output.build(metroServer, requestOptions); + } finally { + await metroServer.end(); + } if (options.onComplete) { options.onComplete(); @@ -337,7 +343,6 @@ exports.runBuild = async (options: RunBuildOptions) => { }; await output.save(metroBundle, outputOptions, console.log); - await metroServer.end(); return {metroServer, metroBundle}; };