-
Notifications
You must be signed in to change notification settings - Fork 100
ESM isn't published correctly #127
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
🎉 This issue has been resolved in version 1.0.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Thanks for your report @dburles! We don't have a dual package hazard concern in this package, so we opted for |
Looks great, thanks! |
I am receiving this error in Typescript when attempting to import the client: // lib/sanity/index.ts
import { createClient } from 'next-sanity'
...
This is on It seems the issue stems from Edit: I'm going to leave this here, but it seems the larger issue is the strange behavior with setting "Node16" as the resolution mode. This thread is a bit over my head: microsoft/TypeScript#49083 but it seems this particular method of module resolution is not to be used frivolously. We are going to work around the reasons we needed that import method as it likely implies issues with the modules that needed it. Followup again: I don't know if we can actually refactor the places that require I can confirm at least for our use case, just slapping a |
To further add to the confusion, this error is apparently not there in our netlify deploy which causes it to fail since I used a
unsure if this is some dependency difference or what.. I don't know how to run the same command that NextJS is outside of the build command |
I think this is still an issue with this library, I believe the reason it seemed to "resolve" was because when NextJS builds it apparently forces |
This problem should now be solved in |
As there's no type field set in
package.json
, Node will assume anything with a.js
file extension to be CommonJS and treats the exported ESM as CommonJS.Reproduction:
> npm i next-sanity
> echo 'import { groq } from "next-sanity";' > test.mjs
node test.mjs
Results in:
Solution:
.mjs
, and CommonJS exports to.cjs
(Recommended).or
package.json
type
as "module" (so Node then treats.js
as ESM) and then rename all extensions of commonjs exports to.cjs
.Also, if the package is to remain publishing dual bundles, you need to ensure that there's no dual package hazard.
For more information see the Node.js docs: https://nodejs.org/api/packages.html#dual-commonjses-module-packages
The text was updated successfully, but these errors were encountered: