question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Buffer is not defined

See original GitHub issue

web3modal crashes when WalletConnect is a provider with the following error:

Uncaught ReferenceError: Buffer is not defined
    at Object../node_modules/web3-provider-engine/node_modules/ethereumjs-util/dist/secp256k1-lib/der.js (der.js:6:1)
    at Object.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at Object../node_modules/web3-provider-engine/node_modules/ethereumjs-util/dist/secp256k1-adapter.js (secp256k1-adapter.js:6:1)
    at Object.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at Object../node_modules/web3-provider-engine/node_modules/ethereumjs-util/dist/index.js (index.js:11:1)
    at Object.options.factory (react refresh:6:1)

when using create-react-app version 5.0.0.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
andy191xcommented, Jul 26, 2022

@andy191x worked for me

Glad to hear that! I ended up running into more dependency issues with the missing polyfills. If you end up down that route, there’s a solution with react-app-rewired package ( https://alchemy.com/blog/how-to-polyfill-node-core-modules-in-webpack-5 )

1reaction
andy191xcommented, May 5, 2022

I ran into the same issue when upgrading to React 18 with CRA. This is because the Node polyfills are no longer bundled with webpack. This solution worked for my app:

Install the buffer package:

npm install buffer

Add the following line to index.js:

window.Buffer = require('buffer/').Buffer;

Additional reading:

https://stackoverflow.com/questions/37656592/define-global-variable-with-webpack

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Uncaught ReferenceError: Buffer is not defined
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 · Issue #2248
I am facing a similar error, while trying to include graphql-ws in my app. constants.js:5 Uncaught ReferenceError: Buffer is not defined at ...
Read more >
Buffer is not defined. Using Phantom Wallet ...
This is happening because the default bundler that comes with create react app(webpack 5) does not polyfill Buffer .
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 >
ReferenceError: Buffer is not defined - Questions & Help
Buffer is a global variable set by homeyscript. Now it is not defined anymore. Why do you need the script? If you think...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found