Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing default or module-sync export in package.json #1245

Closed
SimpleCreations opened this issue Oct 31, 2024 · 8 comments · Fixed by #1246
Closed

Missing default or module-sync export in package.json #1245

SimpleCreations opened this issue Oct 31, 2024 · 8 comments · Fixed by #1246

Comments

@SimpleCreations
Copy link

SimpleCreations commented Oct 31, 2024

Description

Latest Node.js now supports requireing pure ESM packages, which is great for all of us who are stuck with CJS due to other dependencies and want to use 7.x.

However, graphql-request's exports field in package.json is too restrictive — it insists on the package being imported via ESM syntax, while in reality it otherwise would work if imported via require(esm).

graffle/package.json

Lines 9 to 15 in ccdae10

"exports": {
".": {
"import": {
"types": "./build/entrypoints/main.d.ts",
"default": "./build/entrypoints/main.js"
}
},

Please consider adding an additional default or module-sync export, or removing import specifier altogether, e.g.

  "exports": {
    ".": {
      "types": "./build/entrypoints/main.d.ts",
      "default": "./build/entrypoints/main.js"
    }
  }

This is done by other pure ESM packages (for example nanoid).

Reproduction Steps/Repo Link

In Node 23:

require("graphql-request");
node:internal/modules/cjs/loader:644
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined
@jasonkuhrt
Copy link
Member

@SimpleCreations Awesome, I also recently heard about this but just vaguely. I'll make a release with the changes you're indicating.

Do you know which Node.js version users need for this to work?

@SimpleCreations
Copy link
Author

SimpleCreations commented Oct 31, 2024

Hi @jasonkuhrt, thank you for quick reply!

require(esm) was added in Node 20.17 and Node 22.0 with --experimental-require-module flag, and also in Node 23.0 without flags. module-sync in package.json is supported since Node 22.10.

The change I'm proposing would be backwards compatible of course.

@jasonkuhrt
Copy link
Member

What is the benefit of module-sync?

When we ship this I'll update our docs for users who don't know

@jasonkuhrt
Copy link
Member

@jasonkuhrt
Copy link
Member

Note you're asking about graphql-request. I will make the change to graffle. Do you need this change in graphql-request too?

@jasonkuhrt
Copy link
Member

jasonkuhrt commented Nov 1, 2024

I also updated graphql-request: https://github.com/graffle-js/graffle/releases/tag/7.1.1

@SimpleCreations
Copy link
Author

Hi @jasonkuhrt! Thank you for the changes — I've tested the update, it works great now! Also glad you removed unnecessary dependencies.
Yes, I've been looking to upgrade graphql-request from v6 to v7 for a while now but the CJS/ESM interop was the roadblock.

@jasonkuhrt
Copy link
Member

Thanks for brining this approach to my attention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants