jasonkuhrt / graphql-request

Minimal GraphQL client
MIT License
5.77k stars 307 forks source link

[7.0.1] broken types #846

Closed efstathiosntonas closed 2 months ago

efstathiosntonas commented 2 months ago

After upgrading to 7.0.1 IDE complains about typings.

Screenshot

Screenshot 2024-05-11 at 11 39 45

Description

Reproduction Steps/Repo Link

AbdUlHamedMaree commented 2 months ago

I opened an issue yesterday and it was closed, and many others, the issue is TypeScript compiler doesn't read the exports field in the package.json yet and relays only on the types field, in the v7 types field got removed

efstathiosntonas commented 2 months ago

closing, duplicate: https://github.com/jasonkuhrt/graphql-request/issues/844

AbdUlHamedMaree commented 2 months ago

@jasonkuhrt I believe we need the types field back, just for backward compatibility

AbdUlHamedMaree commented 2 months ago

@efstathiosntonas but that issue got closed as well 🥲

efstathiosntonas commented 2 months ago

@AbdUlHamedMaree how did you managed to solve this? can you share your tsconfig?

AbdUlHamedMaree commented 2 months ago

@efstathiosntonas just change moduleResolution to be Bundler, but the issue with that, it might break other stuff

efstathiosntonas commented 2 months ago

did that earlier and it breaks everything, got like 200 errors lol.

@jasonkuhrt can you please bring the types back? It's a tremendous breaking change.

AbdUlHamedMaree commented 2 months ago

oh yeah it did break the building process 🥲

jasonkuhrt commented 2 months ago

Have you enabled package.exports on your React Native project? https://reactnative.dev/blog/2023/06/21/package-exports-support

jasonkuhrt commented 2 months ago

And you need to have your TSConfig setup properly https://stackoverflow.com/questions/70296652/how-can-i-use-exports-in-package-json-for-nested-submodules-and-typescript

CleanShot 2024-05-11 at 10 09 17@2x

AbdUlHamedMaree commented 2 months ago

@jasonkuhrt You're totally right, didn't expect types field to be legacy, but yeah using moduleResolution: "bundler" fixed my issue, but afraid of others that relays on TSC to bundle their libraries or applications, Thanks anyway!

Zerebokep commented 2 months ago

Anyone else receives a ERR_PACKAGE_PATH_NOT_EXPORTED error even with correct tsconfig settings?

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /workspace/project/node_modules/graphql-request/package.json

tsconfig

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "strict": true,
    "skipLibCheck": true,
    "lib": ["ESNext"]
  }
}
jasonkuhrt commented 2 months ago

@Zerebokep is that a runtime error or TS error. Looks like a runtime error. Confirm? If so, Node version?

Zerebokep commented 2 months ago

Yup, runtime, I'm using node 22.1.0.

jasonkuhrt commented 2 months ago

Then it's not about broken types. New issue welcome, thanks!

Zerebokep commented 2 months ago

Strangely it works on another container with a similar setup, I'm even using the same tsconfig there. Not sure if it's relevant, but I'm using pnpm as package manager and tsx to execute the script. I've also checked the package.json of graphql-request node_modules folder, it's identical for both containers, exports are included.