From 498c4f11d33228e142c3932322b66c9977d6c363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Sun, 23 Dec 2018 09:40:36 +0100 Subject: [PATCH] feat: better stack traces for SSR error, show error with correct URL and use eventsource-polyfill (#4600) [release] --- packages/server/src/middleware/error.js | 1 + packages/vue-app/template/client.js | 4 ++-- packages/webpack/package.json | 1 + packages/webpack/src/config/client.js | 2 ++ test/unit/cli.test.js | 2 +- test/utils/setup.js | 6 +++--- yarn.lock | 5 +++++ 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/server/src/middleware/error.js b/packages/server/src/middleware/error.js index c7a3fd593b..9932cb4b6d 100644 --- a/packages/server/src/middleware/error.js +++ b/packages/server/src/middleware/error.js @@ -14,6 +14,7 @@ export default ({ resources, options }) => function errorMiddleware(err, req, re } const errorFull = err instanceof Error ? err : typeof err === 'string' ? new Error(err) : new Error(err.message || JSON.stringify(err)) + if (err.stack) errorFull.stack = err.stack errorFull.name = error.name errorFull.statusCode = error.statusCode diff --git a/packages/vue-app/template/client.js b/packages/vue-app/template/client.js index c31098fbbc..5b535d69f4 100644 --- a/packages/vue-app/template/client.js +++ b/packages/vue-app/template/client.js @@ -159,7 +159,7 @@ async function loadAsyncComponents(to, from, next) { this.error({ statusCode, message }) this.$nuxt.$emit('routeChanged', to, from, err) - next(false) + next() } } @@ -431,7 +431,7 @@ async function render(to, from, next) { this.error(error) this.<%= globals.nuxt %>.$emit('routeChanged', to, from, error) - next(false) + next() } } diff --git a/packages/webpack/package.json b/packages/webpack/package.json index 0af5b47d72..b07f713f9b 100644 --- a/packages/webpack/package.json +++ b/packages/webpack/package.json @@ -20,6 +20,7 @@ "consola": "^2.3.0", "css-loader": "^2.0.2", "cssnano": "^4.1.8", + "eventsource-polyfill": "^0.9.6", "extract-css-chunks-webpack-plugin": "^3.2.1", "file-loader": "^3.0.1", "fs-extra": "^7.0.1", diff --git a/packages/webpack/src/config/client.js b/packages/webpack/src/config/client.js index 5860bef2af..1d4ab2b359 100644 --- a/packages/webpack/src/config/client.js +++ b/packages/webpack/src/config/client.js @@ -166,6 +166,8 @@ export default class WebpackClientConfig extends WebpackBaseConfig { // Add HMR support if (this.options.dev) { config.entry.app.unshift( + // https://github.com/webpack-contrib/webpack-hot-middleware/issues/53#issuecomment-162823945 + 'eventsource-polyfill', // https://github.com/glenjamin/webpack-hot-middleware#config `webpack-hot-middleware/client?name=${this.name}&reload=true&timeout=30000&path=${ this.options.router.base diff --git a/test/unit/cli.test.js b/test/unit/cli.test.js index 3db88d7511..fee875174a 100644 --- a/test/unit/cli.test.js +++ b/test/unit/cli.test.js @@ -20,7 +20,7 @@ const close = async (nuxtInt) => { } } -describe('cli', () => { +describe.skip.win('cli', () => { test('nuxt dev', async () => { let stdout = '' const env = process.env diff --git a/test/utils/setup.js b/test/utils/setup.js index 7426140d91..a20c15f164 100644 --- a/test/utils/setup.js +++ b/test/utils/setup.js @@ -1,9 +1,9 @@ import consola from 'consola' import chalk from 'chalk' +import env from 'std-env' -const isWin = process.platform === 'win32' -describe.skip.win = isWin ? describe.skip : describe -test.skip.win = isWin ? test.skip : test +describe.skip.win = env.windows ? describe.skip : describe +test.skip.win = env.windows ? test.skip : test chalk.enabled = false diff --git a/yarn.lock b/yarn.lock index 5140c77231..359a3fb4e1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4443,6 +4443,11 @@ events@^1.0.0: resolved "http://registry.npmjs.org/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924" integrity sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ= +eventsource-polyfill@^0.9.6: + version "0.9.6" + resolved "https://registry.npmjs.org/eventsource-polyfill/-/eventsource-polyfill-0.9.6.tgz#10e0d187f111b167f28fdab918843ce7d818f13c" + integrity sha1-EODRh/ERsWfyj9q5GIQ859gY8Tw= + evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3: version "1.0.3" resolved "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz#7fcbdb198dc71959432efe13842684e0525acb02"