From 88615152fb0ff010743f194b2d3a493e28fdbd2b Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Fri, 5 May 2023 14:57:21 -0400 Subject: [PATCH] fix(nextjs): enable Next.js 13.4 support (#16819) --- 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) {