React Toastify not recognized as an ES module
See original GitHub issueDo 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:
- Add type: “module” to the package.json and replace the
js
extension withcjs
for the CommonJS output. - Replace the
js
extension withmjs
for the ES module outputreact-toastify.esm.js
.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Ok, thanks. I’m running a couple of tests with your PR and I will merge it if everything is ok. Thanks a lot!
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