ReferenceError: File is not defined
Unanswered
Johnny posted this in #help-forum
JohnnyOP
Whenever I reference the type "File" in my project, I get "ReferenceError: File is not defined" at the time of building a standalone output (docker deployment). The error only happens when building the docker image. It does not happen if I run "npm run build" locally.
Upon removal of all the File type references, the error disappears.
Example code that uses the File type (a zod schema):
I am attaching the error of the build as an image.
Upon removal of all the File type references, the error disappears.
Example code that uses the File type (a zod schema):
const updateProductSchema = z.object({
productId: z.string(),
name: z.string(),
description: z.string(),
price: z.coerce.number(),
image: z.instanceof(File),
url: z.string()
});I am attaching the error of the build as an image.
9 Replies
What is file here?
Is it the js type or a custom type you created. (I assume the former)
JohnnyOP
It is the built in type that represents files
I am using it for receiving files from a form. The schema in the code snippet is for validating form data in a server action.
I am not exactly sure what the issue is but what i could collect:
I think its because its trying to somehow run it on the server, and Node doesn't have
So you'll have to make a check here to see if you're on the client or not
I think its because its trying to somehow run it on the server, and Node doesn't have
File, your browser api does(the client).So you'll have to make a check here to see if you're on the client or not
JohnnyOP
The thing is I have to use "any" server-side, and I would prefer to avoid that.
Welp, i dont know a way around that, but atleast you know what the issue is

JohnnyOP
Thank you for your help 🙂