17

When ever I attempt importing tosify into react:

Using the following:

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

I get the following error:

Failed to compile.

./node_modules/react-toastify/dist/react-toastify.esm.mjs Can't import the named export 'cloneElement' from non EcmaScript module (only default export is available)

Not sure what solution is and have spent alot time trying to find solution but I am unable too, if anything else is needed let me know but when the tosify import not there the site works fine.

1
  • I deleted nod_modules and package-lock.json and run 'yarn' instead. Everything worked Commented Jul 11, 2023 at 12:08

9 Answers 9

16

Try by changing the version to older version of toastify. Manually add this in your package.json file "react-toastify": "^8.1.0", , and then run npm i then again run npm start.

Sign up to request clarification or add additional context in comments.

Comments

9

As stated in this bug report, this seems to be an issue that appears when react-toastify is used with older versions of react-scripts.

Your options are:

  • upgrade to the newest version of react-scripts (version 5 or above)
  • downgrade react-toastify to version 9.0.3, which seems to still work with older versions of react-scripts

Comments

4

All you need to do is this

npm i [email protected]

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
1

I faced the same issue in React 18.2.0, which was fixed by:

#upgrading to the latest version of react-scripts
npm install [email protected]  # OR npm install --save react-scripts@latest

#if you encounter errors after upgrading.
rm -r node_modules
npm install

Comments

0

It seems to be some kind of error because of node version. Could you try to reproduce this with latest node version? Don't forget to remove node_modules and yarn.lock | package-lock.json

Comments

0

I solved by updating my node version and react version,

npm install --save react@latest npm install -g npm-check-updates npm audit fix --force

Comments

0

I had the same problem, I have tried to update my yarn , and react versions , but the problem was still there. the best way is to downgrade toastify version to 8.0.0, and it will work.

Comments

0

Just use this as import import 'react-toastify/dist/ReactToastify.css';

Comments

0

everything worked for me when i used the ToasterContainer with self closing tag like this :

<ToasterContainer/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.