[BUG] Facing runtime error when using latest version with Next.js 12.2.4 and node v10
Bug description I integrated the latest version (5.22.0) of the react-tooltip library in a Next.js project. I'm running into below error related to how the resolution of the package's exports is happening when Next.js builds my App:
Error:
file:///app/node_modules/react-tooltip/dist/react-tooltip.min.mjs:7
SyntaxError: The requested module 'react' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export.
I searched for similar issues for other libraries when using them with Next.js, and found this one: 39375. But I couldn't find a solution for this for my setup.
Any help on this issue would be highly appreciated 🙏
Version of Package v5.22.0
Next.js Version: 12.2.4 Node version: v10
Update:
After going through the discussion in the thread on https://github.com/vercel/next.js/issues/39375 , I tried the below change, and it made the error go away:
- I copied over
dist/react-tooltip.min.mjsto my repo and renamed it toreact-tooltip.min.js, i.e, rename from.mjsextension to.js. After this change, the above issue is not happening.
For the time being I'm using this temporary workaround, I'm not sure why .mjs extension would cause the above issue though.
We're already aware of a similar issue (probably closely related) with create-react-app not supporting .cjs files. See #1067 and our troubleshooting section.
For now, there's not much we can do, since the shift towards .cjs/.mjs/... over plain .js extensions is something that's already happening, and we'd like to follow the trend.
We'll keep this open for now and see if we figure out better ways to work around it in the future.
Are you still experiencing this issue? If so, are you able to upgrade to the latest NextJS version (14.0.4 as of right now) and let us know if that fixes it?
@gabrieljablonski Upgrading to the NextJS version (currently 14.0.4) did not resolve the issue
This issue is stale because it has not seen activity in 30 days. Remove the stale label or comment within 14 days, or it will be closed.