question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Toastify not recognized as an ES module

See original GitHub issue

Do you want to request a feature or report a bug?

I think this is a bug with the bundle.

What is the current behavior?

React Toastify is not recognized as an ES module. The build of an next application with react toastify will fail with the following error.

SyntaxError: Named export 'ToastContainer' not found. The requested module 'react-toastify' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'react-toastify';

What is the expected behavior?

It should not fail with this error and just load the ES module.

Demo-Repo

https://github.com/openpatch/patches-nextjs-starter/tree/dcd30554da8c1cd393a8c15be4f2d4c6ae8777c8

Solution

I think the filename is not correct. Since this package does not specify, that it is a module via the type field in the package json. The js will interpret as a CommonJS module. See here: https://github.com/developit/microbundle#usage-with-typemodule-in-packagejson.

There are two solutions to the problem:

  1. Add type: “module” to the package.json and replace the js extension with cjs for the CommonJS output.
  2. Replace the js extension with mjs for the ES module output react-toastify.esm.js.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fkhadracommented, May 29, 2022

Ok, thanks. I’m running a couple of tests with your PR and I will merge it if everything is ok. Thanks a lot!

0reactions
fkhadracommented, May 29, 2022

Ok, I’ll close the issue for now but keep your PR open. If more people encounter the same issue, I’ll use your PR. Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Toastify Module not found - Stack Overflow
Please use following commands: First install using this and import it. npm i react-toastify import {ToastContainer,toast} from ...
Read more >
[CRA v4] Can't import the named export 'cloneElement' from ...
The main issue is that CRA v4 does not support es module. ... cool, I fixed the version of react-toastify to 9.0.3 when...
Read more >
react-toastify - npm
Start using react-toastify in your project by running `npm i ... There are 1519 other projects in the npm registry using react-toastify.
Read more >
react toastify can't import the named export 'cloneelement'
React Toastify is not recognized as an ES module. The build of an next application with react toastify will fail with the following...
Read more >
ReactJS Toast Notification - GeeksforGeeks
Step 3: Now import react-toastify module, toastify CSS file, and a caller method of toast notification. Step 4: In your app.js file, add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found