Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

react-toastify: toast() runs but nothing shows, or it looks broken

Errortoast() is called, no toast appears on screen

Short answer

react-toastify needs one ToastContainer rendered once in your tree, and styles. Before v11 you import the CSS file yourself; since v11 it is injected for you. Check that the container is mounted, that the CSS import matches your version, and that React is 18 or newer.

  • Applies to react-toastify 10 and 11, React 18, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check the installed version first. It decides whether you need the CSS import.

    npm ls react-toastify react
  2. 2Match what you see, then jump to its fix

    1. 1toast() runs without any error and nothing appearsNo ToastContainer is mountedFix
    2. 2The toast shows as plain text with no box, colour or animationVersion 10 or older without the stylesheet importFix
    3. 3You upgraded to v11 and still import ReactToastify.minimal.css or ReactToastify.cssVersion 11 and a leftover import pathFix
    4. 4npm ls shows a React version below 18React is older than 18Fix

What does the error look like?

  • toast() is called, no toast appears on screen
  • toast appears as plain unstyled text at the bottom of the page
  • toasts worked before upgrading react-toastify to v11 and now look wrong

Cause 1 of 4

No ToastContainer is mounted

1Check

The docs say to render the container once, and to put it at the root of the application if unsure. Search for it.

grep -rn "ToastContainer" src/

2Fix

Render one ToastContainer in your root component, next to the rest of the app, and call toast() from anywhere.

import { ToastContainer, toast } from 'react-toastify';

function App() {
  return (
    <>
      <button onClick={() => toast("Saved")}>Save</button>
      <ToastContainer />
    </>
  );
}

3Verify

Click the button; a toast appears in the top right.

npm run dev

Confirmed by fkhadra.github.io

Did this fix it?

Cause 2 of 4

Version 10 or older without the stylesheet import

1Check

Up to v10 the usage example imports the CSS file next to the components.

grep -rn "ReactToastify.css" src/

2Fix

Add the import once, in the file where you render the container.

import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

3Verify

Reload the page and trigger a toast; it has its styling.

npm run dev

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 4

Version 11 and a leftover import path

1Check

The v11 migration guide says the stylesheet is injected automatically, so the import is no longer needed, and the minimal stylesheet was removed.

grep -rn "ReactToastify" src/

2Fix

Delete the CSS import lines. The styles come with the package.

// remove these lines
// import 'react-toastify/dist/ReactToastify.css';
// import 'react-toastify/dist/ReactToastify.minimal.css';

3Verify

Rebuild; there is no missing-file error and the toast is styled.

npm run build

Confirmed by fkhadra.github.io

Did this fix it?

Cause 4 of 4

React is older than 18

1Check

The installation page lists React 18 or above as the requirement.

npm ls react

2Fix

Upgrade React and react-dom to 18 or newer, or install a react-toastify version that supports your React.

npm install react@latest react-dom@latest

3Verify

npm ls shows react 18 or newer, and the toast works.

npm ls react react-dom

Confirmed by fkhadra.github.io

Did this fix it?

How do I stop it coming back?

  • Read the migration guide when you bump the major version of a UI library.
  • Mount the container once in the root, never inside a page that re-renders or unmounts.
  • Add a one-line test that renders the app and calls toast() so a missing container is caught.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.