← All tasks
javascriptpillarjs/iconv-lite #263Not a task: already works

Error: 'global is not defined'

envgap__pillarjs__iconv-lite-263

01 / FAILURE SIGNATURE

As reported upstream

When importing `iconv-lite` (v0.6.2) in an Angular 10 app I'm getting this error:
Not a benchmark task.
  • The project already builds and runs before the fix, so there is nothing to repair.

02 / ENVIRONMENT RECIPE

Base commit
72d6d72f2d3f04a6603c07700df6822a6e57a9be
Manifest
package.json
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

pillarjs/iconv-lite #263 · read the original issue
When importing `iconv-lite` (v0.6.2) in an Angular 10 app I'm getting this error:



```js

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](https://github.com/ChALkeR/safer-buffer), but whilst it gets fixed, a workaround for this is adding this line in [index.js](https://github.com/ashtuchkin/iconv-lite/blob/v0.6.2/lib/index.js#L3):



```js

// node_modules/iconv-lite/lib/index.js

window.global = window;  // Add this just before importaing safer-buffer

var Buffer = require("safer-buffer").Buffer;

```
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]