From 3ef8a670aee04c357a01849c067addd606e5d39b Mon Sep 17 00:00:00 2001 From: Pepijn Senders Date: Fri, 30 Apr 2021 08:45:25 -0700 Subject: [PATCH] Don't swallow MODULE_NOT_FOUND error (#24577) ## Bug - [x] Related issues linked using [`fixes #24328`](https://github.com/vercel/next.js/pull/24328#issuecomment-828847472) - [ ] Integration tests added The change in #24328 will swallow any `MODULE_NOT_FOUND` errors triggered in the page. If you for example have a page with a broken import, it will tell you `Error: Failed to load /whatever`. This of course doesn't really tell people what is going on internally (a broken import). I added a check to see if the error actually happened in the page. --- .../next/next-server/server/load-components.ts | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/next/next-server/server/load-components.ts b/packages/next/next-server/server/load-components.ts index f7d361ef9c608..14ad0a11170f5 100644 --- a/packages/next/next-server/server/load-components.ts +++ b/packages/next/next-server/server/load-components.ts @@ -74,20 +74,9 @@ export async function loadComponents( } as LoadComponentsReturnType } - let DocumentMod - let AppMod - let ComponentMod - - try { - DocumentMod = await requirePage('/_document', distDir, serverless) - AppMod = await requirePage('/_app', distDir, serverless) - ComponentMod = await requirePage(pathname, distDir, serverless) - } catch (err) { - if (err.code === 'MODULE_NOT_FOUND') { - throw new Error(`Failed to load ${pathname}`) - } - throw err - } + const DocumentMod = await requirePage('/_document', distDir, serverless) + const AppMod = await requirePage('/_app', distDir, serverless) + const ComponentMod = await requirePage(pathname, distDir, serverless) const [ buildManifest,