-
Notifications
You must be signed in to change notification settings - Fork 267
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 import when moduleResolution: node16
is set for typescript
#354
Comments
In demo/ts-module-node16/tsconfig.json, we used {
"compilerOptions": {
"esModuleInterop": true,
"module": "Node16",
"strict": true,
}
} Otherwise, please look at the demo and try to find what's different. |
Unfortunately having The difference with the new moduleResolutions settings is, to my understanding, typescript now only considers the I tried all the typescript configuration combinations, unfortunately none of them is covering all the usecases.
|
Having a hard time understanding the exact need. I am not a TS user myself, just trying to help. Could you create a demo similar to ts-module-node16. Fork the repository, duplicate the Note, my initial understand was wrong. I have tried to use dynamic import with |
Sure, thanks for considering my case! I am off for a couple of weeks, after that I'll create the fork and will attempt to alter the configuration to match my needs without breaking any of the demos. Do you mind if I keep the ticket open until then? |
No worry, I am myself on holidays as well. In order to not break any demo, just |
I'm pretty sure the issue here is the |
Hum, that is an interesting possibility. |
I'm having a similar problem as well when using those CSV packages in a CJS context. I'm still not sure that's the whole story, but if I got this right, the issue is that To reproduce the problem, just do this: https://github.com/acidoxee/node-csv/commit/4e6cf591715a8dc8823989e435b5c079d6ad56a8, and look at the error on the import here: https://github.com/acidoxee/node-csv/blob/4e6cf591715a8dc8823989e435b5c079d6ad56a8/demo/ts-module-node16/lib/stringify.ts#L3. I don't think there's any use to forcing those The only appropriate fix here seems to yield matching See this comment and its whole thread which seems to confirm this behavior. |
Does having both the "module" and "moduleResolution" set to "Node16" could resolve the issue ? |
Otherwise, could someone reproduce the issue in a branch inside a dedicated "./demo/{package}". Reproducing the issue would help finding a solution |
With #368 merged, the following settings work for us:
"module": "ES2022",
"moduleResolution": "node16",
"type": "module",
import { parse } from 'csv-parse/sync'
import { stringify } from 'csv-stringify/sync' |
OK, then let's close it. |
That's great for ESM! Although when consuming When writing Wouldn't there be a way for you to generate those declaration files in |
If you provide me with a project example illustrating the issue inside the "demo" folder, then I'll be happy to generate the ".d.cts" files. |
@wdavidw I've added a demo illustrating the issue: https://github.com/jonmast/node-csv/tree/master/demo/ts-moduleresolution-node16-cjs Running: I believe this happens with the combination of |
Thanks for the demo @jonmast, and sorry for not getting back to you @wdavidw! Another thing I haven't tried is putting the
I'm not sure if this really has an effect or not, but might as well follow their instructions on that matter. |
Validated, could you create a merge request with the demo folder, I'll merge it and make the changes in the mean time |
Could we rename the demo with a short name, also, I don't think node 16 has anything to do with test, I tested the same behavior with Node 18 and 19 and tsconfig mention |
Sure, I can rename it. You are correct that the error isn't node version specific, it is from Typescript's "node16" resolver which was built to be compatible with the new module resolver in node 16 but also applies to newer releases. |
The following packages were updated:
|
I renamed it to "ts-cjs-node16" |
Describe the bug
Getting
when trying to import in a project with
moduleResolution: node16
.To Reproduce
package.json
tsconfig.json
main.ts
and then run:
Output I get:
Additional context
My intent in this example is to import csv-parse using require, but typescript seems to think this library only exposes esm modules.
Typescripts esm support is not without controversies. One of them is that they are more strict about the location of
.d.ts
files: microsoft/TypeScript#49160 . The most straightforward solution seems to be just duplicating the type definitions beside all entry points, but there might be better ways I am not aware of.The text was updated successfully, but these errors were encountered: