Open t-animal opened 3 months ago
Hi @tvillaren do you have an ETA for a fix for this?
Hello,
Not really. I you have a solution in mind, please feel free to open a PR! 🙏 Thanks!
Fwiw, I saw that detection for this setting is already in the codebase, somewhere. I can't work on this atm, though....
Be great to get a simple fix for this, because it makes it actually totally unusuable in Deno in certain situations (when importing other files, it MUST have the extension, you can't just import it without). This causes issues when you have multiple files relying on another.
I did have a sed workaround, but that only works in certain situations.
To elaborate, this will fail in the validation step in certain cases, specifically for me it's when using an enum as zod wants to infer back to the original enum, but cannot and so ts-to-zod fails in the validation step and never generates the code (so we can't use sed).
For future reference: The code for detecting if the project has type: "module"
is already here and I think the fix could be applied here, when actually writing the import to the output string or probably rather here, when creating the import node
Bug description
ts-to-zod does not include the filename in such a scenario, making it incompatible with "module"-packages running in node.
When running in node (i.e. not targeting a bundler/webbrowser), the typescript "module"-property must be set to
"node16"
or"nodenext"
. When usingtype:"module"
inpackage.json
, this means that imports have to include the ".js" suffix.A minimal example would be:
Running tsc gives the following error:
Our current solution is to fix the imports using
sed
in our build-script:Input
Multiple files containing types, referencing each other. E.g:
Expected output
a.zod.ts
should be:Actual output
Versions