diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index 475f5b16d029..24eca3b1c2d7 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -2248,6 +2248,7 @@ export default async function getBaseWebpackConfig( appDir, dev, isEdgeServer, + useExperimentalReact, })), hasAppDir && !isClient && diff --git a/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts b/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts index 943700b00519..48b396ea4428 100644 --- a/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts @@ -32,11 +32,13 @@ import { import { traverseModules, forEachEntryModule } from '../utils' import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep' import { getProxiedPluginState } from '../../build-context' +import { warnOnce } from '../../../shared/lib/utils/warn-once' interface Options { dev: boolean appDir: string isEdgeServer: boolean + useExperimentalReact: boolean } const PLUGIN_NAME = 'ClientEntryPlugin' @@ -75,11 +77,13 @@ export class ClientReferenceEntryPlugin { dev: boolean appDir: string isEdgeServer: boolean + useExperimentalReact: boolean constructor(options: Options) { this.dev = options.dev this.appDir = options.appDir this.isEdgeServer = options.isEdgeServer + this.useExperimentalReact = options.useExperimentalReact } apply(compiler: webpack.Compiler) { @@ -241,6 +245,11 @@ export class ClientReferenceEntryPlugin { } if (actionEntryImports.size > 0) { + if (!this.useExperimentalReact) { + warnOnce( + '\nServer Actions require `experimental.experimentalReact` option to be enabled in your Next.js config.\n' + ) + } addActionEntryList.push( this.injectActionEntry({ compiler, diff --git a/test/e2e/app-dir/actions/app/server/form.js b/test/e2e/app-dir/actions/app/server/form.js index 82860e06a71d..a8ba60bff0c9 100644 --- a/test/e2e/app-dir/actions/app/server/form.js +++ b/test/e2e/app-dir/actions/app/server/form.js @@ -14,15 +14,15 @@ export default function Form() { return ( <>
-
- + +

-
+