ts-to-zod
ts-to-zod copied to clipboard
Types validation are not working on Ubuntu
Bug description
When ever I try to generate types I get an error. Zod and ts-to-zod are both installed. What am I doing wrong?
Input
➜ git:(develop) ✗ npx ts-to-zod ./src/types/client.ts ./src/types/client.ts
✖ Validating generated types
› Error: File '/.../source.ts' is not a module.
Versions
- Typescript:
v4.4.3
- Zod:
v3.9.1
Strange 🤔
Do you have allowSyntheticDefaultImports: true
in your tsconfig.json
? (the only thing I can thing of ^^)
Edit: I tried, this is also working… (worst case you can add --skipValidation
but I still want to understand…)
What version of nodejs do you have?
Do you have
allowSyntheticDefaultImports: true
in yourtsconfig.json
? (the only thing I can thing of ^^)
No, I tried adding both true
and false
, but still the same issue.
Edit: I tried, this is also working… (worst case you can add
--skipValidation
but I still want to understand…)
It works with this, but it still should work without it.
What version of nodejs do you have?
Node version 14.17.7
I can repro in codesanbox, this is maybe a nodejs issue (I’m on 12.22.6
locally)
So… probably somewhere here -> https://github.com/fabien0102/ts-to-zod/blob/1e13bbbd6daa608b43ed4bd5209d3cd723001fe3/src/core/validateGeneratedTypes.ts#L112-L114
Can you add some dirty console.log in node_modules
to see the value of process.cwd
and join(…)
?
Can you add some dirty console.log in
node_modules
to see the value ofprocess.cwd
andjoin(…)
?
I replaced the directory (which is the correct root folder) and this is the response:
function getPath(file) {
const x = path_1.join(process.cwd(), file.relativePath)
console.log(process.cwd(), x)
return x;
}
--------------------------------------
/DIR /DIR/source.zod.ts
/DIR /DIR/source.integration.ts
/DIR /DIR/source.ts
/DIR /DIR/source.zod.ts
/DIR /DIR/source.integration.ts
/DIR /DIR/source.integration.ts
/DIR /DIR/source.integration.ts
None of these files exists
They do exists, in a virtual file system 😅 (we are creating those files to check if the types are correct but without writing any file)
Anyway, I can repro on codesandbox… this is very strange and unexpected, I actually tried with node 14 locally, and this is working, on which operating system are you?
Hmm, this is weird then. I am using Ubuntu 21.04.
I’m on windows, I tried on a WSL (Ubuntu 21 like you) and this is working, but codesandbox seams to have the same issue 😅
I guess this will be good enough for debugging, even if playing with vim
to hack node_module is not the best DX 😓
Thanks for the reporting anyway, and sorry for this really unexpected issue, I will try to find a fix quickly (you can also give a try if you have some idea)
Thanks for looking into it so quickly.
I'm okay for now running it with --skipValidation
for now, so just take your time.
Normally the library is well tested, this is just to help me to find some little edge cases 😉
Hi, Just to let you know, I'm seeing this on MacOS, node v14.17.6.
I think we have the major desktop OSs covered :)
And I'm seeing the same in PowerShell and cmd on Windows. I also see it when running PS or cmd as admin.
(node v14.17.6)
... good work and awesome tool btw 👍
I’m currently working on #42 (some edge cases are very challenging 😅) and I’m having a look on this one (also happy if somebody open an amazing PR that fix this 😇)
Thanks for the reporting!
I'm able to get ts-to-zod
working in one of two scenarios.
- package.json has
"type": "module"
tsconfig must have "module": "es2020"
but should also have "moduleResolution": "node"
and "esModuleInterop": true
- package.json does not have
"type": "module"
tsconfig must have "module": "commonJS"
If you don't have the right combination of settings, you get the same error reported by @kladnik when trying to run ts-to-zod
Any workaround for this issue other than skipValidation?
I'm having the same bug on ts-to-zod/2.0.1 darwin-arm64 node-v19.5.0
, with zod v3.20.2
. It happens both on running the global binary (i.e. ts-to-zod in.ts out.ts
) and when running npx
inside a NPM project with ts-node
installed