diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index b14888080a377..f96f20f6228a0 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -960,8 +960,10 @@ export default async function build( let ssgPageRoutes: string[] | null = null let isMiddlewareRoute = !!page.match(MIDDLEWARE_ROUTE) - const pagePath = pagePaths.find((_path) => - _path.startsWith(actualPage + '.') + const pagePath = pagePaths.find( + (p) => + p.startsWith(actualPage + '.') || + p.startsWith(actualPage + '/index.') ) const pageRuntime = hasConcurrentFeatures && pagePath @@ -974,7 +976,7 @@ export default async function build( if ( !isMiddlewareRoute && !isReservedPage(page) && - // We currently don't support staic optimization in the Edge runtime. + // We currently don't support static optimization in the Edge runtime. pageRuntime !== 'edge' ) { try { diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 1446dccb00cf8..33b3bdf0a34e8 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -981,6 +981,7 @@ export default async function getBaseWebpackConfig( ...(isEdgeRuntime ? [ { + '@builder.io/partytown': '{}', 'next/dist/compiled/etag': '{}', 'next/dist/compiled/chalk': '{}', 'react-dom': '{}', diff --git a/packages/next/build/webpack/loaders/utils.ts b/packages/next/build/webpack/loaders/utils.ts index c0628c568154d..e28e02eaea041 100644 --- a/packages/next/build/webpack/loaders/utils.ts +++ b/packages/next/build/webpack/loaders/utils.ts @@ -14,6 +14,7 @@ export function buildExports(moduleExports: any, isESM: boolean) { const esmNodeTypes = [ 'ImportDeclaration', + 'ExportDeclaration', 'ExportNamedDeclaration', 'ExportDefaultExpression', 'ExportDefaultDeclaration', diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx index 57a5f4a24af33..1b1885121ef1a 100644 --- a/packages/next/pages/_document.tsx +++ b/packages/next/pages/_document.tsx @@ -79,7 +79,8 @@ function hasComponentProps(child: any): child is React.ReactElement { function getPreNextWorkerScripts(context: HtmlProps, props: OriginProps) { const { assetPrefix, scriptLoader, crossOrigin, nextScriptWorkers } = context - if (!nextScriptWorkers) return null + // disable `nextScriptWorkers` in edge runtime + if (!nextScriptWorkers || process.browser) return null try { let {