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: global is not defined #217

Open
MunMunMiao opened this issue Nov 11, 2019 · 9 comments
Open

ReferenceError: global is not defined #217

MunMunMiao opened this issue Nov 11, 2019 · 9 comments

Comments

@MunMunMiao
Copy link

example

import { toCanvas } from 'qrcode'
class XXX{
    ngOnInit(){
        toCanvas(this.qrcode.nativeElement, this.order.payurl, {width: 200})
    }
}

console

core.js:6014 ERROR Error: Uncaught (in promise): ReferenceError: global is not defined
ReferenceError: global is not defined
    at Object../node_modules/buffer/index.js (index.js:43)
    at __webpack_require__ (bootstrap:790)
    at fn (bootstrap:150)
    at Object../node_modules/qrcode/lib/core/reed-solomon-encoder.js (reed-solomon-encoder.js:3)
    at __webpack_require__ (bootstrap:790)
    at fn (bootstrap:150)
    at Object../node_modules/qrcode/lib/core/qrcode.js (qrcode.js:10)
    at __webpack_require__ (bootstrap:790)
    at fn (bootstrap:150)
    at Object../node_modules/qrcode/lib/browser.js (browser.js:4)
    at resolvePromise (zone-evergreen.js:793)
    at resolvePromise (zone-evergreen.js:752)
    at zone-evergreen.js:854
    at ZoneDelegate.invokeTask (zone-evergreen.js:400)
    at Object.onInvokeTask (core.js:39688)
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Zone.runTask (zone-evergreen.js:168)
    at drainMicroTaskQueue (zone-evergreen.js:570)

Angular: 8
node-qrcode: 1.4.4

@MatissJanis
Copy link

Experiencing the same issue. Downgrading to v1.4.3 solved it for me.

@Roen00
Copy link

Roen00 commented Nov 12, 2019

I faced the same issue.
This is probably related to this change:
6058f49#diff-5ad6b95c7f35b51922edb67db4c2f400R3
As a temporary workaround I added this to my index.html:

  <script>
    if (global === undefined) {
      var global = window;
    }
  </script>

@soldair
Copy link
Owner

soldair commented Nov 13, 2019

thanks for the report. ill land a patch to fix this now.
this is unexpected because the bundles i generate for the browser without webpack work perfectly. it's likely because i use browserify.

@soldair
Copy link
Owner

soldair commented Nov 13, 2019

https://github.com/feross/buffer/blob/master/index.js doesn't contain the line that errored.

I changed the require such that Buffer will always use the universally compatible version instead of node's and im interested in seeing what happens.

HELP: would someone mind sharing a webpack config they use with qrcode so i can add a pre-publish integration test.

@soldair soldair reopened this Nov 13, 2019
@soldair
Copy link
Owner

soldair commented Nov 13, 2019

can folks test on master because i don't have a reproduction of the issue.
if not ill land this as 1.4.5 and hope for the best

@MunMunMiao
Copy link
Author

@soldair i want test it ,but i can not install node-gyp😓, now i used 1.4.2, it's working in angular8

@mnahkies
Copy link

I investigated this in relation to using with Angular applications here:
mnahkies/ng-qrcode#2 (comment)

tldr; with respect to Angular applications this appears to be caused by @angular-devkit/build-angular depending on a older version of webpack, and workaround will be required until this is no longer the case.

qrcode itself depends on a fixed version of buffer now, but individual projects webpack configuration / other dependencies could interfere in a similar way to what I describe with Angular.

@soldair
Copy link
Owner

soldair commented Dec 13, 2019

Thanks so much. I'll take a look at this and see if I can come up with something

@janbiasi
Copy link

Any update @soldair ?

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