react-toastify: Error: React is not defined
Do you want to request a feature or report a bug?
bug
What is the current behavior?
Using react-toastify with @vitejs/plugin-react v2.0.0 and vite v3.0.0 throws
ReferenceError: React is not defined only in Production.
After getting the error, I enabled sourcemap and found the error in react-toastify esm build.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your CodeSandbox (https://codesandbox.io/s/new) example below:
Use @vitejs/plugin-react v2.0.0 and vite v3.0.0 and use toast.error('message') and you’ll get the error
What is the expected behavior? It shouldn’t throw. Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? It works in both react 17 and 18 when using vite v2 but it’s throwing in vite 3 as vite 3 uses esm.
I’m not sure if it’s a vitejs plugin but or react-toastify. Lmk should I create the issue in vitejs plugin instead.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 21 (9 by maintainers)
Commits related to this issue
- fix #797 disable minification — committed to fkhadra/react-toastify by fkhadra 2 years ago
- [Snyk] Upgrade react-toastify from 9.0.7 to 9.1.3 (#585) <p>This PR was automatically created by Snyk using the credentials of a real user.</p><br /><h3>Snyk has created this PR to upgrade react-to... — committed to MTES-MCT/monitorenv by thoomasbro a year ago
@imranbarbhuiya pushed v9.0.7
Awesome I’ll publish a new version tomorrow then
Yeah yarn was resolving it to
9.0.6. I just tried by pinning the version and it worked. Thanks.I’ll test with your repo btw have you tried in production build or dev build? Because the dev build works fine the issue comes in the production build.