userbase icon indicating copy to clipboard operation
userbase copied to clipboard

Error "Buffer2 is undefined" when using userbase-js with SvelteKit

Open zPhoeniqz opened this issue 3 years ago • 3 comments

Full error message:



Buffer2 is undefined

node_modules/safe-buffer/index.js@http://localhost:3000/node_modules/.vite/deps/userbase-js.js?v=4f8aa8dd:174:9 __require@http://localhost:3000/node_modules/.vite/deps/chunk-QOVRSCHT.js?v=4f8aa8dd:11:50 node_modules/randombytes/browser.js@http://localhost:3000/node_modules/.vite/deps/userbase-js.js?v=4f8aa8dd:230:19 __require@http://localhost:3000/node_modules/.vite/deps/chunk-QOVRSCHT.js?v=4f8aa8dd:11:50 node_modules/diffie-hellman/lib/generatePrime.js@http://localhost:3000/node_modules/.vite/deps/userbase-js.js?v=4f8aa8dd:3261:23 __require@http://localhost:3000/node_modules/.vite/deps/chunk-QOVRSCHT.js?v=4f8aa8dd:11:50 node_modules/diffie-hellman/browser.js@http://localhost:3000/node_modules/.vite/deps/userbase-js.js?v=4f8aa8dd:3543:25 __require@http://localhost:3000/node_modules/.vite/deps/chunk-QOVRSCHT.js?v=4f8aa8dd:11:50 @http://localhost:3000/node_modules/.vite/deps/userbase-js.js?v=4f8aa8dd:6155:37


To reproduce:


npm init svelte@next
npm install
npm install userbase-js


Edit the index.svelte file. Add following line:


import userbase from 'userbase-js'

zPhoeniqz avatar Apr 27 '22 21:04 zPhoeniqz

Going to look into removing the diffie-hellman dependency since it shouldn't be in use anymore anyway (was only used in userbase-js v1), thanks for reporting.

j-berman avatar Apr 30 '22 19:04 j-berman

+1 for this. Is there any workaround that can be used in the meantime?

BlakeEric avatar May 27 '22 11:05 BlakeEric

One workaround in the meantime could be to import the script from https://sdk.userbase.com/2/userbase.js

I'm not too familiar with Svelte, but this post seems a solid guide on going about doing that

j-berman avatar May 28 '22 21:05 j-berman