YousefED / Matrix-CRDT

Use Matrix as a backend for local-first applications with the Matrix-CRDT Yjs provider.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Buffer is not defined error

ysds opened this issue · comments

"When I run the "todo-simple-react" example and try to add a todo, I get the following error.

This may be related to this.
webpack/changelog-v5#10

image

Thanks @ysds,

Do you get the same error on https://klwxt.csb.app/, or only when you build it yourself?

The current version of Matrix-CRDT doesn't use webpack anymore (we have migrated to Vite)

Sorry for the late reply.
I was unable to open the demo for a while due to the "TypeError Could not fetch dependencies, please try again in a couple of seconds" issue in codesandbox.

Now I can access that demo without any problem and I can't confirm the Buffer issue.

Also, I raised my local Node version from v16 to v18 and this problem did not occur.

I'm seeing the same issue when trying to set this up with a SvelteKit/Vite project.

"matrix-crdt": "^0.2.0",
"matrix-js-sdk": "^22.0.0",

I added this Buffer polyfill to get around the problem for now:
https://github.com/feross/buffer

I see there's another location in the code using lib0/buffer.fromBase64 which seems like it might be a suitable replacement for the base64 encoding/decoding that would work in the browser without a polyfill.

commented

Added a Vite example now that shows how you can set it up, see this note in the main Readme:

Note for Vite / non-webpack If you're using Vite, or other non-webpack builds, note that matrix-js-sdk depends on certain polyfills available. See the Vite example and matrix-org/matrix-js-sdk#2903.