avsc icon indicating copy to clipboard operation
avsc copied to clipboard

How to use avsc with Angular 6? Buffer is not defined error

Open damonwildercarr opened this issue 8 years ago • 3 comments

We recently moved to Angular 6 which has a webpack config that does not provide node globals like 'Buffer' (as described here https://webpack.js.org/configuration/node/). Therefore we immediately broke after the upgrade to 6.

I'm declaring avsc as such:

const avro = require('avsc/etc/browser/avsc-types');

More info on Angular 6 turning off the webpack node option:

more information: https://github.com/angular/angular-cli/issues/9827

If I introduce the hack described here (changing that webpack node variable) things work again:

https://blog.lysender.com/2018/07/angular-6-cannot-resolve-crypto-fs-net-path-stream-when-building-angular/

This is the error at run-time:

Uncaught ReferenceError: Buffer is not defined at new BufferPool (utils.js:243) at Object../node_modules/avsc/lib/utils.js (utils.js:14) at webpack_require (bootstrap:76) at Object../node_modules/avsc/lib/types.js (types.js:17) at webpack_require (bootstrap:76) at Object../node_modules/avsc/etc/browser/avsc-types.js (avsc-types.js:11) at webpack_require (bootstrap:76) at Object../src/app/pdpackage/avroparser/logicaltypes.ext.ts (logicaltypes.ext.ts:4) at webpack_require (bootstrap:76) at Object../src/app/pdpackage/avroparser/pimcoavrohttp.service.ts (logicaltypes.ext.ts:271)

image

Thanks, Damon

damonwildercarr avatar Aug 21 '18 22:08 damonwildercarr

Got this working by adding the following:

In Index.html:

In polyfills.ts:

global.Buffer = global.Buffer || require('buffer').Buffer;

(window as any).process = { env: { DEBUG: undefined }, };

damonwildercarr avatar Aug 23 '18 21:08 damonwildercarr

Great to hear - thank you for the update @damonwildercarr!

mtth avatar Aug 24 '18 02:08 mtth

Got this working by adding the following:

In Index.html:

In polyfills.ts:

global.Buffer = global.Buffer || require('buffer').Buffer;

(window as any).process = { env: { DEBUG: undefined }, };

Thank you very much!

agiletuan avatar Mar 23 '19 20:03 agiletuan