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

Error: 'global is not defined' #263

Open
RaschidJFR opened this issue May 12, 2021 · 2 comments
Open

Error: 'global is not defined' #263

RaschidJFR opened this issue May 12, 2021 · 2 comments

Comments

@RaschidJFR
Copy link

When importing iconv-lite (v0.6.2) in an Angular 10 app I'm getting this error:

Uncaught ReferenceError: global is not defined
    at Object../node_modules/buffer/index.js (my-component.js:238)
    at __webpack_require__ (runtime.js:85)
    at Object../node_modules/safer-buffer/safer.js (my-component.js:8266)
    at __webpack_require__ (runtime.js:85)
    at Object../node_modules/iconv-lite/lib/index.js (my-component.js:7768)
    at __webpack_require__ (runtime.js:85)
    at Module../src/my-component.ts (my-component.js:11618)
    at __webpack_require__ (runtime.js:85)
    at Object.1 (my-component.js:11705)
    at __webpack_require__ (runtime.js:85)

It looks like the error comes from the dependency safer-buffer, but whilst it gets fixed, a workaround for this is adding this line in index.js:

// node_modules/iconv-lite/lib/index.js
window.global = window;  // Add this just before importaing safer-buffer
var Buffer = require("safer-buffer").Buffer;
@RaschidJFR
Copy link
Author

I've created a hotfix but can't create a PR because it is not up to date with master and master is now too far from this version. So If anyone runs across this issue, you can use this fix for now:

npm install raschidjfr/iconv-lite#hotfix/v0.6.3

@TheThing
Copy link

TheThing commented Jun 8, 2021

Because of the removal of safer-buffer with #265 this might be auto fixed in the next version.

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

2 participants