fix: gracefully handle unhandled promises

This prevents nuxt process exiting in dev mode on unhandled promises
This commit is contained in:
Pooya Parsa 2017-07-09 16:13:56 +04:30
parent 4bf0a46cb0
commit 85825d190c
2 changed files with 11 additions and 5 deletions

View File

@ -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)

View File

@ -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()