Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

der.ts:6 Uncaught ReferenceError: Buffer is not defined #255

Open
SyedImam1998 opened this issue Jun 20, 2022 · 2 comments
Open

der.ts:6 Uncaught ReferenceError: Buffer is not defined #255

SyedImam1998 opened this issue Jun 20, 2022 · 2 comments

Comments

@SyedImam1998
Copy link

SyedImam1998 commented Jun 20, 2022

I am facing this issue when i used
import { encrypt } from '@metamask/eth-sig-util';
i am facing this error
i have also tried
import {Buffer} from 'buffer';
Can someone please guide me here?

image

`

@mcmire
Copy link

mcmire commented Jun 21, 2022

Hi @SyedImam1998, I saw your comment in the other issue. No need to create another issue if it is related. I am going to paste the comment I left there:

Buffer is a class in the Node standard library, so it works in a Node context, but in a browser context, you will probably need to configure your preprocessor to replace this with a polyfill. If you're using Webpack, then you can:

  1. Install the buffer module.
  2. Configure Webpack to use it via the resolve.fallback option. This should allow you to use Buffer in your own code.
  3. Configure Webpack with ProvidePlugin. This should fix dependencies like ethereumjs-util so that anywhere Buffer appears, it is automatically replaced with the class exported by buffer.

Hope that helps. Let me know if you encounter any more issues.

@Ian-Bright
Copy link

Ian-Bright commented Aug 5, 2022

Hey @mcmire would you mind providing an example? I have tried the steps you described but still cannot get Buffer recognized. Here is my webpack.config.js file

module.exports = {
  resolve: {
    fallback: {
      buffer: require.resolve('buffer/'),
    },
  },
  plugins: [
    new webpack.ProvidePlugin({
      Buffer: ['buffer', 'Buffer'],
    }),
  ],
};

EDIT: I was able to solve this by using craco but still would would love to know what is incorrect about my configuration :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants