react-toastify: toast() runs but nothing shows, or it looks broken
toast() is called, no toast appears on screenShort 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.
Fix it fast
1Find out which cause you have
Check the installed version first. It decides whether you need the CSS import.
npm ls react-toastify react2Match what you see, then jump to its fix
- 1
toast() runs without any error and nothing appearsNo ToastContainer is mountedFix - 2
The toast shows as plain text with no box, colour or animationVersion 10 or older without the stylesheet importFix - 3
You upgraded to v11 and still import ReactToastify.minimal.css or ReactToastify.cssVersion 11 and a leftover import pathFix - 4
npm ls shows a React version below 18React is older than 18Fix
- 1
What does the error look like?
toast() is called, no toast appears on screentoast appears as plain unstyled text at the bottom of the pagetoasts 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 devConfirmed by fkhadra.github.io
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 devConfirmed by raw.githubusercontent.com
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 buildConfirmed by fkhadra.github.io
Cause 4 of 4
React is older than 18
1Check
The installation page lists React 18 or above as the requirement.
npm ls react2Fix
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@latest3Verify
npm ls shows react 18 or newer, and the toast works.
npm ls react react-domConfirmed by fkhadra.github.io
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fixWeb apps
Axios request is not cancelled when a React component unmounts
A cancelled request is logged as an error in the catch block
Axios cancels a request when you pass it an AbortSignal and later call abort() on its controller.
4 causes, each with a fix