From 6d7f6318a1219a9aee46758be82c925aae4fb168 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Fri, 5 May 2023 13:15:23 -0400 Subject: [PATCH] fix(nextjs): enable Next.js 13.4 support --- packages/next/plugins/with-nx.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/next/plugins/with-nx.ts b/packages/next/plugins/with-nx.ts index 2d991e049a385..482087e305b55 100644 --- a/packages/next/plugins/with-nx.ts +++ b/packages/next/plugins/with-nx.ts @@ -156,6 +156,15 @@ function withNx( _nextConfig = {} as WithNxOptions, context: WithNxContext = getWithNxContext() ): NextConfigFn { + // If this is not set user will see compile errors in Next.js 13.4. + // See: https://github.com/nrwl/nx/issues/16692, https://github.com/vercel/next.js/issues/49169 + // TODO(jack): Remove this once Nx is refactored to invoke CLI directly. + forNextVersion('>=13.4.0', () => { + process.env['__NEXT_PRIVATE_PREBUNDLED_REACT'] = + // Not in Next 13.3 or earlier, so need to access config via string + _nextConfig.experimental['serverActions'] ? 'experimental' : 'next'; + }); + return async (phase: string) => { const { PHASE_PRODUCTION_SERVER } = await import('next/constants'); if (phase === PHASE_PRODUCTION_SERVER) {