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. image

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

Most upvoted comments

@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.

It seems to work just fine for me, so I believe it has something to do with the configuration

fkhadra/vite-toastify

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.