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

ReferenceError: Buffer is not defined #215

Closed
anuj9196 opened this issue Nov 5, 2019 · 7 comments
Closed

ReferenceError: Buffer is not defined #215

anuj9196 opened this issue Nov 5, 2019 · 7 comments

Comments

@anuj9196
Copy link

anuj9196 commented Nov 5, 2019

I'm trying to get it to work in Angular 8.

In the component.ts file

import QRCode from 'qrcode`;

export class MyComponent implements OnInit {
    ngOnInit() {
        const canvas = document.getElementById('canvas');
        QRCode.toCanvas(canvas, 'Hello World', (res) => {
            console.log('res: ', res);
         });
    }
}

But this is giving an error:

ReferenceError: Buffer is not defined
    at ReedSolomonEncoder.encode (reed-solomon-encoder.js:37)
    at createCodewords (qrcode.js:340)
    at createData (qrcode.js:286)
    at createSymbol (qrcode.js:424)
    at Object.create (qrcode.js:498)
    at browser.js:53
    at new ZoneAwarePromise (polyfills.js:3725)
    at renderCanvas (browser.js:51)
@lyxia
Copy link

lyxia commented Nov 5, 2019

+1

@soldair
Copy link
Owner

soldair commented Nov 5, 2019

thanks I just released a version yesterday that probably introduced this.
ill take a look now

@soldair
Copy link
Owner

soldair commented Nov 5, 2019

please try version 1.4.4 and let me know

@anuj9196
Copy link
Author

anuj9196 commented Nov 6, 2019

@soldair Thanks. It's working now.

@anuj9196 anuj9196 closed this as completed Nov 6, 2019
@davidknoll
Copy link

@soldair I've just found this issue and I'm experiencing it or something similar on 1.2.2, 1.3.4, 1.4.0-1.4.4, and master at eb2d499. I'm using AngularJS 1.5.8, with qrcode in the frontend/browser, and the error appears in the browser debug console. On some versions of qrcode the root component of my app won't instantiate, on some it only triggers once I try to use it.

@plumpNation
Copy link

If anyone is coming here from a rollup project, https://www.npmjs.com/package/rollup-plugin-node-builtins

@james-innes
Copy link

As per this discussion around node-globals/node-builtins I found rollup-plugin-node-polyfills got the QR code working for me using Rollup with Svelte.

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

6 participants