feross / buffer

The buffer module from node.js, for the browser.
Other
1.8k stars 234 forks source link

writeBigUInt64BE is not a function #301

Closed dekadentno closed 3 years ago

dekadentno commented 3 years ago

I am trying to access writeBigUInt64BE like in the codesandbox below: https://codesandbox.io/s/stoic-bohr-bnsir

but the error states that

Buffer.prototype.writeBigUInt64BE is not a function

although it is exported as seen here: https://github1s.com/feross/buffer/blob/HEAD/index.js#L1542-L1543 Functions like writeIntLE are exported in the same way and they can be accessed.

Note: typeof BigInt returns function in my browser.

vweevers commented 3 years ago

You may need import { Buffer } from "buffer/" (note the slash) rather than import { Buffer } from "buffer", in order to import the buffer npm package rather than the shim that the bundler injects, which may be an older version of buffer.

dekadentno commented 3 years ago

Thank you for your answer. I managed to do that in my codesandbox above, but writeBigUInt64BE is still undefined in my local vue project.

Steps to reproduce error:

git clone https://github.com/dekadentno/buffer-test
cd buffer-test
npm i
npm run serve

I know this may not be the place to ask this, but I hope you may know the answer. I also assume this may be a webpack/babel issue, but I cannot be certain.

dekadentno commented 3 years ago

The issue was in the import. Even import { Buffer } from "buffer/" // notice the slash didn't help me, I had to import it this way import { Buffer } from 'buffer/index.js' because it was picking up node_modules/node-libs-browser/node_modules/buffer/index.js instead of node_modules/buffer/index.js.

I don't know if it should be noted in the docs and if anyone had a similar issue.