ant-design: Ant Design Component Causing Error ReactRender Is Not A Function

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  1. Create a new project using Next.js 15.
  2. Install antd version 5.22.5.
  3. Wrap root layout with <AntdRegistery>
  4. Import the Button component from antd into the page.tsx file.
  5. Use the Button component in that Page.
  6. Run the application using npm run dev.

What is expected?

When I click the button, the onClick function attached to the button should be executed without errors, and no TypeError or other issues should occur.

What is actually happening?

When I use the button from antd (So far I only use the button), when I click on it, the TypeError error occurs: reactRender is not a function.

I’ve checked it works regardless of whether you use the client or the server. I am using extjs 15 and the latest version of antd. I also tried to create a new clean next project and try it there, but the error is the same.

Environment Info
antd 5.22.5
React 19.0.0
System Nextjs 15
Browser Chrome:latest

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 24 (1 by maintainers)

Most upvoted comments

I tried this (https://ant.design/docs/react/v5-for-19) workaround, however after installing the package and adding import "@ant-design/v5-patch-for-react-19"; in either the root layout.tsx or directly in the target component, I started getting another error:

Export unstableSetRender doesn't exist in target module. It looks like this module is not present in the antd package. Any ideas?

Full error:

./node_modules/.pnpm/@ant-design+v5-patch-for-react-19@1.0.3_antd@5.22.5_react-dom@19.0.0_react@19.0.0__react@19.0_woot36jsp3wkv2wbpd2supzpya/node_modules/@ant-design/v5-patch-for-react-19/es/index.js:3:1
Export unstableSetRender doesn't exist in target module
  1 | 'use client';
  2 |
> 3 | import { unstableSetRender } from 'antd';
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4 | import { createRoot } from 'react-dom/client';
  5 | unstableSetRender(function (node, container) {
  6 |   container._reactRoot || (container._reactRoot = createRoot(container));

The export unstableSetRender was not found in module [project]/node_modules/.pnpm/antd@5.22.5_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/antd/es/index.js [app-client] (ecmascript) <exports>.
Did you mean to import Table?
All exports of the module are statically known (It doesn't have dynamic exports). So it's known statically that the requested export doesn't exist.

Update: Make sure that you are on "antd": "^5.23.1" or above, since if you are below that, you will run into the same issue as me.

yes when click happens image

Applying @ant-design/v5-patch-for-react-19 – didn’t help, the error didn’t go away. However, I was able to add a workaround by rendering the portal components as in the following code:

import { ReactElement, StrictMode } from 'react';
import { createRoot, Root } from 'react-dom/client';
import { unstableSetRender } from "antd/lib/config-provider/UnstableContext";
import App from './App';
import "./style/index.scss";

/**
 * Creates the main React root and targets the HTML element with the id="root".
 */
const root: Root = createRoot(document.getElementById('root') as HTMLElement);

/**
 * Renders the React application within the created root.
 */
root.render(
    <StrictMode>
        <App/>
    </StrictMode>
);

/**
 * Maintain a mapping between portal container elements and their React roots.
 * This prevents calling `createRoot` more than once on the same container.
 */
const portalRoots = new WeakMap<Element | DocumentFragment, Root>();

/**
 * Overrides the default patch of rendering behavior for Ant Design portal components.
 * IMPORTANT: Will be removed after adding React 19 support out-of-the-box.
 *
 * @param node – The React element to render in the portal.
 * @param container – The DOM container where the element should be rendered.
 * @returns A cleanup function to unmount the portal.
 */
unstableSetRender((node: ReactElement, container: Element | DocumentFragment) => {

    // Try to retrieve an existing root for this container
    let portalRoot = portalRoots.get(container);

    // If no root exists yet, create one and store it in the map
    if (!portalRoot) {
        portalRoot = createRoot(container);
        portalRoots.set(container, portalRoot);
    }

    // Render or update the portal with the provided React element
    portalRoot.render(node);

    // Return a cleanup function that unmounts the portal and removes it from the map
    return async () => {
        await new Promise((resolve) => setTimeout(resolve, 0));
        portalRoot?.unmount();
        portalRoots.delete(container);
    };
});

dependencies: “react”: “19.0.0”, “react-dom”: “19.0.0”, “antd”: “5.24.1”,

P.S. I definitely think the antd team (@afc163) needs to add a full-fledged example of using unstableSetRender, particularly for typescript projects.

It seems like you’re encountering a TypeError with the message “reactRender is not a function” when using the Ant Design Button component in a Next.js 15 project. This error might be related to compatibility issues between the versions of React, Next.js, and Ant Design you’re using.

Here are a few steps you can take to troubleshoot and potentially resolve the issue:

  1. Check React Version Compatibility: Ensure that the version of React you’re using is compatible with Ant Design 5.22.5. The error message suggests a potential mismatch or missing dependency.

  2. Verify Ant Design Installation: Double-check that Ant Design is installed correctly. You can try reinstalling it using npm install antd@5.22.5.

  3. Review Next.js Configuration: Ensure that your Next.js configuration is set up correctly to work with Ant Design. This includes checking if any custom webpack configurations might be affecting the build.

  4. Check for Known Issues: Look for any known issues or discussions in the Ant Design GitHub repository or community forums that might relate to this error.

  5. Simplify the Setup: Try creating a minimal setup with just the Button component to isolate the issue. This can help determine if the problem is with the integration or a specific part of your project.

  6. Update Dependencies: Ensure all your dependencies are up to date, including React, Next.js, and Ant Design.

If these steps do not resolve the issue, it might be helpful to search for similar issues in the Ant Design GitHub repository to see if others have encountered and resolved this problem. If the issue persists, you may consider opening a new issue with detailed reproduction steps for further assistance.

If you need more specific guidance, please let me know!

🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.

For me it was resolved by returning to react ^ 18

antD can show some compatibility issues if u are using react ^19, so, first, check your react version in package.json, if your react version is 19, this command might help you:

first, you should run this script in your frontend package terminal:

npm install --save-dev @ant-design/v5-patch-for-react-19

and then, you have to import the antd compatibility patch in your jsx archive, just like this:

import ‘@ant-design/v5-patch-for-react-19’;

image +1 “react”: “^18”, “antd”: “^5.22.5”, “next”: “15.1.2”,

Issue is still there on 5.22.5. Pops up when clicking an AntD button.

It seems like you are encountering a TypeError with the message “reactRender is not a function” when using the Ant Design Button component in a Next.js 15 project. This issue might be related to compatibility between the versions of React, Next.js, and Ant Design you are using.

Here are a few steps you can take to troubleshoot and potentially resolve the issue:

  1. Check React Version: Ensure that the version of React you are using is compatible with Ant Design 5.22.5. The error message suggests that there might be an issue with the rendering process, which could be due to an incompatible React version.

  2. Verify Ant Design Setup: Make sure that Ant Design is correctly set up in your project. This includes ensuring that the CSS is properly imported and that any necessary configurations for server-side rendering (SSR) with Next.js are in place.

  3. Update Dependencies: Sometimes, updating your dependencies to the latest versions can resolve compatibility issues. Ensure that you are using the latest stable versions of React, Next.js, and Ant Design.

  4. Check for Known Issues: Look for any known issues or bug reports related to the versions you are using. This can be done by searching the Ant Design GitHub repository for similar issues.

  5. Simplify the Setup: Try creating a minimal reproduction of the issue by stripping down your setup to the bare essentials. This can help identify if there is a specific part of your setup causing the problem.

  6. Consult Documentation: Review the documentation for Ant Design and Next.js to ensure that you are following the recommended practices for integrating these libraries.

If these steps do not resolve the issue, you may want to provide more detailed information about your setup or consider reaching out to the community for further assistance.

If you have any more questions or need further assistance, feel free to ask!

🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.