valibot
valibot copied to clipboard
blob is not defined
I get an error when trying to validate a blob from a input file, regardless or whether it is empty or not.
import {blob,object} from 'valibot'
import {decode} from 'decode-formdata'
const schema = object({file: blob()})
const data = decode(formData, {files:['file']})
const result = safeParse(schema, data)
ReferenceError: Blob is not defined
at Object._parse (file:///C:/repo/node_modules/.pnpm/[email protected]/node_modules/valibot/dist/index.js:570:30)
at Object._parse (file:///C:/repo/node_modules/.pnpm/[email protected]/node_modules/valibot/dist/index.js:2130:31)
at Proxy.safeParse (file:///C:/repo/node_modules/.pnpm/[email protected]/node_modules/valibot/dist/index.js:3689:25)
at default (C:/repo/src/routes/+page.server.ts:34:42)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Module.handle_action_json_request (C:/repo/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/runtime/server/page/actions.js:57:16)
at async resolve (C:/repo/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/runtime/server/respond.js:415:18)
at async Object.handle (C:/repo/src/hooks.server.ts:17:10)
at async Module.respond (C:/repo/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/runtime/server/respond.js:282:20)
The problem is that your runtime is not aware of Blob
. Can you describe where and how you execute Valibot? According to MDN, Blob
should by available in all modern browsers as well as in Deno and Node.js. Could it be that you are using an old version of Node.js?
I am on node16, that is most likely the problem.
Is it possible to set minimum requirements for this package? Or a polyfill?
Please try to add a polyfill on your own first or update your node version. But it is a good hint. If that's the problem, we should mention it in our docs once we add the API reference to it.
I will add a note to our source code to document this in the long run.