From 85825d190c37dafec1d9751a374b3b5df62526d5 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 9 Jul 2017 16:13:56 +0430 Subject: [PATCH] fix: gracefully handle unhandled promises This prevents nuxt process exiting in dev mode on unhandled promises --- bin/nuxt | 11 +++++++++++ bin/nuxt-dev | 5 ----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/nuxt b/bin/nuxt index 04764d440f..42217249cb 100755 --- a/bin/nuxt +++ b/bin/nuxt @@ -1,5 +1,9 @@ #!/usr/bin/env node +// Node Source Map Support +// https://github.com/evanw/node-source-map-support +require('source-map-support').install() + const join = require('path').join const defaultCommand = 'dev' @@ -21,4 +25,11 @@ if (commands.has(cmd)) { const bin = join(__dirname, 'nuxt-' + cmd) +// Console error unhandled promises +process.on('unhandledRejection', function (err) { + /* eslint-disable no-console */ + console.error(err) + console.error('[nuxt] Unhandled promise rejection: ' + err) +}) + require(bin) diff --git a/bin/nuxt-dev b/bin/nuxt-dev index 63a2df52f9..cb50c7397d 100755 --- a/bin/nuxt-dev +++ b/bin/nuxt-dev @@ -54,11 +54,6 @@ const nuxtConfigFile = resolve(rootDir, argv['config-file']) const nuxtConfig = loadNuxtConfig() _.defaultsDeep(nuxtConfig, { watchers: { chokidar: { ignoreInitial: true } } }) -// Fail if an error happened -process.on('unhandledRejection', function (err) { - throw err -}) - // Start dev let dev = startDev()