facebook/react · error · Error

act(...) is not supported in production builds of React.

Error message

act(...) is not supported in production builds of React.

What it means

React's act() testing helper only ships in development builds; the production/minified channel replaces it with a stub that throws immediately when called. React intentionally disables act() in production because IS_REACT_ACT_ENVIRONMENT and the act queue only exist in DEV.

Source

Thrown at packages/react/src/ReactAct.js:252

      return {
        then(resolve: T => mixed, reject: mixed => mixed) {
          didAwaitActCall = true;
          if (prevActScopeDepth === 0) {
            // If the `act` call is awaited, restore the queue we were
            // using before (see long comment above) so we can flush it.
            ReactSharedInternals.actQueue = queue;
            queueMacrotask(() =>
              // Recursively flush tasks scheduled by a microtask.
              recursivelyFlushAsyncActWork(returnValue, resolve, reject),
            );
          } else {
            resolve(returnValue);
          }
        },
      };
    }
  } else {
    throw new Error('act(...) is not supported in production builds of React.');
  }
}

function popActScope(
  prevActQueue: null | Array<RendererTask>,
  prevActScopeDepth: number,
) {
  if (__DEV__) {
    if (prevActScopeDepth !== actScopeDepth - 1) {
      console.error(
        'You seem to have overlapping act() calls, this is not supported. ' +
          'Be sure to await previous act() calls before making a new one. ',
      );
    }
    actScopeDepth = prevActScopeDepth;
  }
}

View on GitHub (pinned to eafeac097b)

Solutions

  1. Run tests with NODE_ENV=test (Jest sets this by default) or development
  2. Make the test setup resolve 'react'/'react-dom' to the development CJS builds (e.g. jest.moduleDirectories, or remove aliases to *.production.min.js)
  3. If testing a built bundle, build it in development mode for the test pass

Example fix

// before (jest.config.js)
module.exports = { testEnvironment: 'node' }; // run with NODE_ENV=production -> act throws

// after
// package.json
"scripts": { "test": "cross-env NODE_ENV=test jest" }
// or ensure no resolver alias like:
// react -> react/cjs/react.production.min.js
Defensive patterns

Strategy: validation

Validate before calling

// Skip act-dependent logic in production builds
const isDevAct = typeof IS_REACT_ACT_ENVIRONMENT !== 'undefined' || process.env.NODE_ENV !== 'production';
if (isDevAct) {
  await act(async () => { renderSomething(); });
} else {
  renderSomething(); // no act in production bundles
}

Prevention

When it happens

Trigger: Calling act(...) while the resolved 'react' module is a production build — e.g. NODE_ENV=production during tests, or a test importing an app bundle built in production mode.

Common situations: Jest config or CI setting NODE_ENV=production; tests that import a prebuilt/minified bundle (dist file) instead of source; Vite/Webpack test setups aliasing react to its .production.min entry.

Related errors


AI-assisted analysis of facebook/react@eafeac097b (2026-08-21). Data as JSON: /api/errors/54a499b246f2f52d. Report an issue: GitHub.