How to use avsc with Angular 6? Buffer is not defined error
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)

Thanks, Damon
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 }, };
Great to hear - thank you for the update @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 }, };
Thank you very much!