one of my dependencies is using "buffer"

Now I can make it work in the browser?
6 Replies
lxsmnsyc
lxsmnsyc2y ago
is your dependency required on the client?
Mentasuave01
Mentasuave01OP2y ago
I think so. This is the error the console is prompting
lxsmnsyc
lxsmnsyc2y ago
do you know which dependency it is? like the direct not indirect if you're using pnpm you can do pnpm why safe-buffer you can also do npm ls safe-buffer
Mentasuave01
Mentasuave01OP2y ago
Dependencies:
pchain-client-js 1.1.7
├─┬ borsh 0.7.0
└─┬ bs58 4.0.1
└─┬ base-x 3.0.9
└── safe-buffer 5.2.1
└─┬ pchain-types-js 3.2.2
└─┬ borsh 0.7.0
└─┬ bs58 4.0.1
└─┬ base-x 3.0.9
└── safe-buffer 5.2.1
Dependencies:
pchain-client-js 1.1.7
├─┬ borsh 0.7.0
└─┬ bs58 4.0.1
└─┬ base-x 3.0.9
└── safe-buffer 5.2.1
└─┬ pchain-types-js 3.2.2
└─┬ borsh 0.7.0
└─┬ bs58 4.0.1
└─┬ base-x 3.0.9
└── safe-buffer 5.2.1
lxsmnsyc
lxsmnsyc2y ago
are you using this directly? seems like the library isn't meant to be used for the browser
Mentasuave01
Mentasuave01OP2y ago
I see, I was looking for a workaround thanks for your time anyways I really appreciate the time and effort I find a workaround in github I post it here for future explorers:
import { Buffer } from 'buffer'
globalThis.Buffer = Buffer`
const { IMPORTED } = await import('YOUR_PACKAGE');
import { Buffer } from 'buffer'
globalThis.Buffer = Buffer`
const { IMPORTED } = await import('YOUR_PACKAGE');
just change Imported and "your package" for whatever you are trying to import
Want results from more Discord servers?
Add your server