supabase-community / chatgpt-your-files

Production-ready MVP for securely chatting with your documents using pgvector
https://youtu.be/ibzlEQmgPPY
362 stars 126 forks source link

Deno function error - ReferenceError: document is not defined #33

Closed audriusl closed 5 months ago

audriusl commented 5 months ago

Bug report

Describe the bug

I am getting this error when running proccess deno function.

runtime has escaped from the event loop unexpectedly: event loop error: ReferenceError: document is not defined at https://esm.sh/v135/decode-named-character-reference@1.0.2/esnext/decode-named-character-reference.mjs:2:7 error in user worker connection: error writing a body to connection failed to send request to user worker: event loop error: ReferenceError: document is not defined at https://esm.sh/v135/decode-named-character-reference@1.0.2/esnext/decode-named-character-reference.mjs:2:7 user worker failed to respond: event loop error: ReferenceError: document is not defined at https://esm.sh/v135/decode-named-character-reference@1.0.2/esnext/decode-named-character-reference.mjs:2:7 InvalidWorkerResponse: event loop error: ReferenceError: document is not defined at https://esm.sh/v135/decode-named-character-reference@1.0.2/esnext/decode-named-character-reference.mjs:2:7 at async Promise.allSettled (index 1) at async UserWorker.fetch (ext:sb_user_workers/user_workers.js:77:21) at async Object.handler (file:///home/deno/main/index.ts:171:14) at async respond (ext:sb_core_main_js/js/http.js:162:14) { name: "InvalidWorkerResponse"

System information

Additional

It seems like there is problem with "fromMarkdow" because it uses decode-named-character-reference.

audriusl commented 5 months ago

I just used other library instead

3dteemu commented 4 months ago

I had this same issue and spent hours trying to figure out what the problem is. For people encountering this in the future, here's what I found.

It seems that when using esm.sh in the import_map.json, it pulls the wrong (browser) content for the decode-named-character-reference. This happens also with the Remark library.

This can be verified by running a debugger and checking what the decode-named-character-reference contains. For me it pulled this content.

Changing the import_map.json from

    ...
    "mdast-util-from-markdown": "https://esm.sh/mdast-util-from-markdown@2.0.1",
    "mdast-util-to-markdown": "https://esm.sh/mdast-util-to-markdown@2.1.0",
    "mdast-util-to-string": "https://esm.sh/mdast-util-to-string@4.0.0",
    ...

to

    ...
    "mdast-util-from-markdown": "npm:mdast-util-from-markdown@2.0.1",
    "mdast-util-to-markdown": "npm:mdast-util-to-markdown@2.1.0",
    "mdast-util-to-string": "npm:mdast-util-to-string@4.0.0",
    ...

solves the problem.

What is strange is that running deno run <your_index.ts> works also with esm.sh, but npx supabase functions serve fails. I don't know why.