0

I am trying to convert my json object to xml using xml-js library and function json2xml. while i try to implement it i am getting an Error as

Error: Buffer is not defined

I am using Angular8.

Please refer to this StackBlitz for Reproducible error.

Please Guide me regarding this. Thanks in Advance.

1

2 Answers 2

1

In your app.module defined this. this will set the Buffer into the global

(window as any).global = window;
declare var require: any;

declare global {
  interface Window {
    Buffer: any;
  }
}

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

@NgModule(...

then in your app.component.ts remove the argument in the xmlc because in your ts. you're not accepting any arguements.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your time and help. i am able to fix the buffer issue.
1

To fix the buffer issue,

npm i buffer

Add these in app.component.ts

import * as buffer from 'buffer'; 
(window as any).global.Buffer = buffer

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.