Skip to content

Error: 'global is not defined' #263

@RaschidJFR

Description

@RaschidJFR

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions