-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
./lib/use/ws' is not defined by "exports" #617
Comments
Starting from v6, those paths have changed to omit the - import { useServer } from 'graphql-ws/lib/use/ws';
+ import { useServer } from 'graphql-ws/use/ws'; |
Thank you @enisdenjo The type script is giving error still and import is from dist ![]() ![]()
|
Try setting the
|
Thank you @enisdenjo |
The code and import is working if you ignore the ts-error - its just the typechecking doesn't work expect in bundler tsconfig. Would it be possible to have exports support commonjs as well |
I tried so many variations of configs - nothing works correctly. The only thing working for me now is
it would be great to have flexibility with other libs and code if possible |
It does work with package.json {
"type": "module",
"version": "1.0.0",
"dependencies": {
"graphql-ws": "^6.0.0",
"typescript": "^5.7.3"
}
} tsconfig.json {
"compilerOptions": {
"module": "node16",
"target": "es2022",
"moduleResolution": "node16"
},
"include": ["index.ts"]
} index.ts import { useServer } from "graphql-ws/use/ws"; Typechecking yields no errors. ✅ However, if changing the project to a Even though graphql-ws has commonjs files: Lines 18 to 57 in 90097bc
It seems to be that TypeScript also requires commonjs types to work in commonjs projects. I'll work on a fix, thanks for reporting! |
Thank you so much @enisdenjo - it works now with node16. But it cause lots of other libs to break - if it's not much to ask if it would be possible to support
|
That configuration is not supported because it is used for very outdated Node, versions older than v12 (v12 official support ended 5 years ago). Supporting that much older version means that the distributed code gets polluted with a lot of polyfils that are simply not necessary in today's stack. Many libraries, including graphql-ws, release major versions once Node reaches end-of-life and bump the least supported engine to the current LTS. Current LTS is v20 which is what graphql-ws requires: Line 15 in e1ec851
I still think that something is simply wrong with your TypeScript configuration, because I doubt you're using Node pre v20. If you can provide me with a repro repository that I can look at, I'd be happy to help. However, if you are using old Node and therefore need TypeScript to generate older code - your only option is downgrading to v5. |
Even TypeScript itself recommends not using |
Yes totally understandable 😊 I was just highlighting that some stable libraries haven't been updated for longtime and this makes them not usable when switching the configs. |
There certainly are workarounds, do you have any specific libraries in mind? If you don't/can't have a repro repository, you can share the error here and I'll see whether I can help you without context. |
Thank you @enisdenjo, For example: https://www.npmjs.com/package/mathjs The typechecking import doesn't work with Node16 config here The only workaround I found is either require('mathjs') or require('graphql-ws') ![]() |
and the issue here happens with any library that doesn't specifically export everything. For example:
Another lib example https://github.com/kysely-org/kysely
there are many other examples :) but i think you got the idea. If supporting commonjs /node10 export won't break anything - I think it's great to add it in so developer don't suffer more with typescript 🙄 |
Sorry for the late reply @meabed, I am quite busy. Here's my input on the given libraries: mathjsThe library does support ESM, but they incorrectly use the package.json#exports field. There's an issue but it seems to be unhandled: josdejong/mathjs#1928. kyselyimport type { DataTypeExpression } from "kysely/dist/cjs/parser/data-type-parser"; Import fails probably because you're direclty importing from - import type { DataTypeExpression } from "kysely/dist/cjs/parser/data-type-parser";
+ import type { DataTypeExpression } from "kysely/dist/esm/parser/data-type-parser"; @google-cloud/storageSame story as with kysely. Sorry, but all these are oversights of the relevant library maintainers. I don't want to take You can always "patch" those libraries with your package manager and rid of these issues by defining correct package.json#exports. |
Error: Package subpath './lib/use/ws' is not defined by "exports" in /node_modules/graphql-ws/package.json
The text was updated successfully, but these errors were encountered: