Urigo / graphql-modules

Enterprise Grade Tooling For Your GraphQL Server
https://graphql-modules.com/
MIT License
1.3k stars 114 forks source link

Package types is not being resolved in a TS setup when `moduleResolution` is `bundler` #2480

Open raulfdm opened 9 months ago

raulfdm commented 9 months ago

Describe the bug

I've noticed that when using graphql-modules in a TypeScript project that defines moduleResolution: "bundler":

{
  "compilerOptions": {
    // ... other config
    "moduleResolution": "Bundler",
    "module": "ESNext",
    "noEmit": true,
  }
}

TypeScript cannot resolve the type definitions:

CleanShot 2023-12-10 at 09 13 41@2x

That's because in the generated dist/package.json, the types field is not present in the exports condition:

image

I won't write all the details here because I saw you're using a tool called bob to generate the final dist, and the problem is there.

I just opened this issue to keep it as a reminder so that when this problem is fixed on the bob's side, you can upgrade it and generate a release.

To Reproduce

  1. Clone this repository: https://github.com/devraul/graphql-modules-type-problem
  2. Follow the README instructions

Expected behavior

Working without a problem in TS configs where it defines the moduleResolution equals bundler

Environment:

Additional context

raulfdm commented 9 months ago

A video demo:

https://github.com/Urigo/graphql-modules/assets/12464600/aad5a32f-abe0-4c4c-b703-c59c9ac0527d

zachariahtimothy commented 9 months ago

Confirmed adding the types to the export sections fixes this. Wondering if we can do a shorter PR in the interim to just add these?

raulfdm commented 9 months ago

Confirmed adding the types to the export sections fixes this. Wondering if we can do a shorter PR in the interim to just add these?

The package.json of graphql-modules already declares the exports.type:

https://github.com/Urigo/graphql-modules/blob/a0893324e00878f0533df61d197379b11ca857c0/packages/graphql-modules/package.json#L17

The problem is that the version of the bundler lib doesn't include this feature. Meaning that the only solution would be upgrading it.

shishkin commented 5 months ago

I was able to workaround this issue with a quick and dirty solution using patch-package and

diff --git a/node_modules/graphql-modules/package.json b/node_modules/graphql-modules/package.json
index 3feda76..d37c95f 100644
--- a/node_modules/graphql-modules/package.json
+++ b/node_modules/graphql-modules/package.json
@@ -30,7 +30,8 @@
   "exports": {
     ".": {
       "require": "./index.js",
-      "import": "./index.mjs"
+      "import": "./index.mjs",
+      "types": "./index.d.ts"
     },
     "./*": {
       "require": "./*.js",
Wroud commented 4 months ago

same problem here

loicnestler commented 3 months ago

Any updates on this? This is killing my ci/cd pipeline :/