Open s-h-a-d-o-w opened 1 year ago
at some point I also thought of just removing the File
altogether as I'm not sure this is worth including or even useful for anyone
I'm fine with both
At the top of the default.hbs file, I added:
const File = (typeof window === "undefined" ? require("buffer").File : window.File) as typeof window.File;
which provides a File
implementation for both Node and Browser environments.
Describe the bug When using the generated code in a server environment (which might obviously become common due to React server components), the following error is thrown:
ReferenceError: File is not defined
Minimal reproduction See this branch: https://github.com/s-h-a-d-o-w/openapi-zod-client-experiment/tree/file-problem-repro
The error is emitted when running the dev server.
Expected behavior I believe the ideal solution would be to generate isomorphic code that looks like the following:
Depending on the use case, the user might obviously have to assert to either
File
orBuffer
but I think that's preferable to the code simply breaking. 😅As you can maybe tell by looking at the rest of the app, I have already tested this approach there.