From 0b921a6b66cfe9268465b48f20ee263f1d071505 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 23 Oct 2022 11:34:53 -0700 Subject: [PATCH] Expose AsyncLocalStorage on global for react (#41683) For compat this needs to be exposed on global in the Node.js runtime as well as discussed cc @sebmarkbage --- packages/next/server/next-server.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/next/server/next-server.ts b/packages/next/server/next-server.ts index 851f57ea8da6e..bad192b6be720 100644 --- a/packages/next/server/next-server.ts +++ b/packages/next/server/next-server.ts @@ -262,6 +262,12 @@ export default class NextNodeServer extends BaseServer { isAppPath: false, }).catch(() => {}) } + + if (this.nextConfig.experimental.appDir) { + // expose AsyncLocalStorage on global for react usage + const { AsyncLocalStorage } = require('async_hooks') + ;(global as any).AsyncLocalStorage = AsyncLocalStorage + } } private compression = this.nextConfig.compress