ReferenceError: Buffer is not defined
See original GitHub issueOn page load I’m getting the error Buffer is not defined
:
It seems to only happen when I’ve imported the '@metamask/eth-sig-util'
script and try to encrypt data:
import ethUtil from 'ethereumjs-util'
import sigUtil from '@metamask/eth-sig-util'
const encryptedData = ethUtil.bufferToHex(
Buffer.from(
JSON.stringify(
sigUtil.encrypt({
publicKey: publicKey,
data: 'hello world data',
version: 'x25519-xsalsa20-poly1305',
})
),
'utf8'
)
)
I’ve tried adding in import { Buffer } from 'buffer/'
, but this doesn’t seem to help.
Chrome version: Version 100.0.4896.88 (Official Build) (64-bit)
on Ubuntu 20 and in FireFox 100.0 (64-bit)
.
If I omit import sigUtil from '@metamask/eth-sig-util'
or
const encryptedData = ethUtil.bufferToHex(
Buffer.from(
JSON.stringify(
sigUtil.encrypt({
publicKey: publicKey,
data: 'hello world data',
version: 'x25519-xsalsa20-poly1305',
})
),
'utf8'
)
)
The error goes away.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
Uncaught ReferenceError: Buffer is not defined - Stack Overflow
Answering my own question. Two things helped to resolve the issue: Adding plugins section with ProviderPlugin into webpack.config.js.
Read more >Uncaught ReferenceError: Buffer is not defined #2248 - GitHub
If you install polyfill buffer package, you get the error: It appears you're using a module that is built in to node, but...
Read more >Buffer is not defined. Using Phantom Wallet, Solana and ...
testing - Uncaught ReferenceError: Buffer is not defined. Using Phantom Wallet, Solana and React to make a transaction - Solana Stack Exchange. ...
Read more >ReferenceError: Buffer is not defined - Homey Community Forum
I am running Homey 7.4.1 and HomeyScript v3.3.0. Restarted HomeyScript and also have restarted Homey. No change. No other installs etc done.
Read more >How to polyfill Buffer with Webpack 5 - viglucci.io
The "buffer is not defined" error is a common error that can occur when trying to use the Buffer Node.js API in an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @SyedImam1998. Did you see my instructions above?
Ah, perfect, that makes sense too! Glad I could help. 😃