valibot icon indicating copy to clipboard operation
valibot copied to clipboard

blob is not defined

Open sacrosanctic opened this issue 1 year ago • 3 comments

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)

sacrosanctic avatar Nov 02 '23 17:11 sacrosanctic

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?

fabian-hiller avatar Nov 02 '23 18:11 fabian-hiller

image

I am on node16, that is most likely the problem.

Is it possible to set minimum requirements for this package? Or a polyfill?

sacrosanctic avatar Nov 03 '23 06:11 sacrosanctic

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.

fabian-hiller avatar Nov 03 '23 15:11 fabian-hiller

I will add a note to our source code to document this in the long run.

fabian-hiller avatar Jun 25 '24 13:06 fabian-hiller