From ae46f82a45277f10a9d060098fb5b204e9e0a365 Mon Sep 17 00:00:00 2001 From: Dorseuil Nicolas Date: Sat, 23 Mar 2024 15:22:28 +0100 Subject: [PATCH] add better error when edge runtime is used inside node --- .../open-next/src/build/copyTracedFiles.ts | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/open-next/src/build/copyTracedFiles.ts b/packages/open-next/src/build/copyTracedFiles.ts index 97928504..d34e7391 100644 --- a/packages/open-next/src/build/copyTracedFiles.ts +++ b/packages/open-next/src/build/copyTracedFiles.ts @@ -70,12 +70,26 @@ export async function copyTracedFiles( const computeCopyFilesForPage = (pagePath: string) => { const fullFilePath = `server/${pagePath}.js`; - const requiredFiles = JSON.parse( - readFileSync( - path.join(standaloneNextDir, `${fullFilePath}.nft.json`), - "utf8", - ), - ); + let requiredFiles; + try { + requiredFiles = JSON.parse( + readFileSync( + path.join(standaloneNextDir, `${fullFilePath}.nft.json`), + "utf8", + ), + ); + } catch (e) { + //TODO: add a link to the docs + throw new Error( + ` +-------------------------------------------------------------------------------- +${pagePath} cannot use the edge runtime. +OpenNext requires edge runtime function to be defined in a separate function. +See the docs for more information on how to bundle edge runtime functions. +-------------------------------------------------------------------------------- + `, + ); + } const dir = path.dirname(fullFilePath); extractFiles( requiredFiles.files,