-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Cannot build TS project when targeting Node16 or NodeNext #1589
Comments
Hi!
I think you might be missing the |
Yes, it's a possible solution, but then I need to rewrite my entire project to be compatible with ESM, which is not the case at the moment. For instance, all my imports doesn't specify the file extension, if I switch to Isn't |
waiting for this... |
I think the root of the problem is that the exports field for the package doesn't define types for the CJS export. I think it should look more like this: ".": {
"import": {
"types": "./build/esm/index.d.ts",
"node": "./build/esm-debug/index.js",
"default": "./build/esm/index.js"
},
"require": {
"types": "./build/cjs/index.d.ts",
"default": "./build/cjs/index.js"
}
}, https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports I think the types need to be duplicated, too, so that the CJS and ESM types have different paths. I found this somewhere in the Typescript docs but can't find it now, so I might be mistaken. Patching the exports field manually worked in my project; I can open a PR if it is helpful. |
This should be fixed by 605de78, included in version 4.7.3. @tylerbutler could you please check? |
Sorry for the delay. I confirmed 4.7.3 works for us, and I was able to remove our patched version. Thank you! |
Describe the bug
When I build my Node.js + Typescript project, I get the following error:
To Reproduce
Here is my project:
index.ts
tsconfig.json
package.json
Expected behavior
I expect to be able to import
socket.io-client
in the same manner as I can importsocket.io
.When I import
socket.io
I don't have any problem:Platform
Additional context
Now you might be wondering why am I importing
socket.io-client
on a Node.js script ?Well because I want to connect to a socket.io server from my terminal ^^
I know I can switch the
module
setting in the tsconfig.json fromNode16
/NodeNext
toCommonJS
to fix this issue, but I think there might be a configuration problem insocket.io-client
that is the root cause of this problem, so I'd rather wait for a proper fix rather than switching toCommonJS
The text was updated successfully, but these errors were encountered: