diff --git a/server/require.js b/server/require.js index a677f870..c1dd480a 100644 --- a/server/require.js +++ b/server/require.js @@ -55,9 +55,17 @@ export function getPagePath (page, {dir, dist}) { export default function requirePage (page, {dir, dist}) { const pagePath = getPagePath(page, {dir, dist}) + try { return require(pagePath) } catch (err) { - throw pageNotFoundError(page) + if (err.code === 'MODULE_NOT_FOUND') { + throw pageNotFoundError(page) + } + console.error(err) + // If this is not a MODULE_NOT_FOUND error, + // it should be something with the content of the page. + // So, Next.js rendering system will catch it and process. + throw err } } diff --git a/test/integration/basic/pages/error-in-the-global-scope.js b/test/integration/basic/pages/error-in-the-global-scope.js new file mode 100644 index 00000000..d821d830 --- /dev/null +++ b/test/integration/basic/pages/error-in-the-global-scope.js @@ -0,0 +1,5 @@ +aa = 10 //eslint-disable-line + +export default () => ( +
Hello
+) diff --git a/test/integration/basic/pages/error.js b/test/integration/basic/pages/error-inside-page.js similarity index 100% rename from test/integration/basic/pages/error.js rename to test/integration/basic/pages/error-inside-page.js diff --git a/test/integration/basic/test/rendering.js b/test/integration/basic/test/rendering.js index 90cf64a4..830f4882 100644 --- a/test/integration/basic/test/rendering.js +++ b/test/integration/basic/test/rendering.js @@ -96,11 +96,16 @@ export default function ({ app }, suiteName, render, fetch) { expect(pre.text()).toMatch(/The default export is not a React Component/) }) - test('error', async () => { - const $ = await get$('/error') + test('error-inside-page', async () => { + const $ = await get$('/error-inside-page') expect($('pre').text()).toMatch(/This is an expected error/) }) + test('error-in-the-global-scope', async () => { + const $ = await get$('/error-in-the-global-scope') + expect($('pre').text()).toMatch(/aa is not defined/) + }) + test('asPath', async () => { const $ = await get$('/nav/as-path', { aa: 10 }) expect($('.as-path-content').text()).toBe('/nav/as-path?aa=10')