From 74512bb03ae27290d8edc6992dea5b7c464c00b2 Mon Sep 17 00:00:00 2001 From: Andrzej Ressel Date: Thu, 1 Jan 2026 21:23:31 +0100 Subject: [PATCH 1/2] Add actionable message for "React.act is not a function" error --- src/act-compat.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/act-compat.js b/src/act-compat.js index 6eaec0fb..3fd5aa16 100644 --- a/src/act-compat.js +++ b/src/act-compat.js @@ -72,6 +72,19 @@ function withGlobalActEnvironment(actImplementation) { return actResult } } catch (error) { + // https://github.com/testing-library/react-testing-library/issues/1392 + // https://github.com/testing-library/react-testing-library/issues/1399 + if ( + Error.isError(error) && + error.toString() === 'TypeError: React.act is not a function' && + process && + process.env.NODE_ENV === 'production' + ) { + throw new Error( + 'Following error may be caused by `NODE_ENV` environment variable being set to `production`. Try changing it to `test`.', + {cause: error}, + ) + } // Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT // or if we have to await the callback first. setIsReactActEnvironment(previousActEnvironment) From 66cfb82cafbeb5bb2e8f74f358f7cd74df1a5009 Mon Sep 17 00:00:00 2001 From: Andrzej Ressel Date: Thu, 1 Jan 2026 21:37:26 +0100 Subject: [PATCH 2/2] Add check for Error.isError --- src/act-compat.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/act-compat.js b/src/act-compat.js index 3fd5aa16..2b4d1168 100644 --- a/src/act-compat.js +++ b/src/act-compat.js @@ -75,6 +75,8 @@ function withGlobalActEnvironment(actImplementation) { // https://github.com/testing-library/react-testing-library/issues/1392 // https://github.com/testing-library/react-testing-library/issues/1399 if ( + // Error.isError is pretty new addition to Node.js - may not be available in LTS versions + Error.isError && Error.isError(error) && error.toString() === 'TypeError: React.act is not a function' && process &&