xml-js icon indicating copy to clipboard operation
xml-js copied to clipboard

Can't resolve 'stream'

Open Mazowiecki opened this issue 6 years ago • 16 comments

WARNING in ./node_modules/xml-js/node_modules/sax/lib/sax.js Module not found: Error: Can't resolve 'stream' in '/home/xxx/xxx/xxx/my-app/node_modules/xml-js/node_modules/sax/lib'

Mazowiecki avatar May 26 '18 20:05 Mazowiecki

Yes, it's a known issue. Please read #54

marcinwadon avatar May 26 '18 20:05 marcinwadon

is that possible that this error causes this: Buffer is not defined at Object.push../node_modules/xml-js/lib/json2xml.js.module.exports [as json2xml] (json2xml.js:4) at AppComponent.push../src/app/app.component.ts.AppComponent.registerUser ?

Mazowiecki avatar May 26 '18 20:05 Mazowiecki

I think no. IMO there must be an error in your code. What's inside your app.component.ts, in registerUser method?

marcinwadon avatar May 26 '18 20:05 marcinwadon

Try to replace your console.log into console.log(xml).

The second thing, firstly you're changing js into xml (js2xml) and then you want to map json to xml (json2xml) using created previously xml. json !== xml so probably that's your answer

marcinwadon avatar May 26 '18 20:05 marcinwadon

My latest post was wrong in all options. What is wrong in this? (the same error): registerUser(form: NgForm) { let xml = JSON.stringify(form.value); console.log(xmljs.json2xml(xml, {compact: true, spaces: 4})); }

Mazowiecki avatar May 26 '18 21:05 Mazowiecki

Please don't delete your comments. It can help others with similar issues

marcinwadon avatar May 26 '18 21:05 marcinwadon

Anyway, I've tried to reproduce your issue and I have the same error:

Buffer is not defined
at push../node_modules/xml-js/lib/json2xml.js.module.exports

marcinwadon avatar May 26 '18 21:05 marcinwadon

Is there another way when it works with Angular?

Mazowiecki avatar May 26 '18 21:05 Mazowiecki

There you can find that Buffer is internal Node.js one.

For your case, don't create json from js object, rather parse js object to xml directly:

registerUser(form: NgForm) {
 console.log(xmljs.js2xml(form.value, {compact: true, spaces: 4}))
}

marcinwadon avatar May 26 '18 21:05 marcinwadon

Also getting this error when building with webpack. It's only a warning, but still annoying that it gets in the way:

WARNING in ./node_modules/sax/lib/sax.js
Module not found: Error: Can't resolve 'stream' in '/home/f.wiles/Documents/soa/node_modules/sax/lib'

Toxicable avatar Jul 19 '18 03:07 Toxicable

Same here!

jblankenhorn avatar Sep 20 '18 13:09 jblankenhorn

I don't understand how #54 is related, but maybe i'm missing context from deleted comments. Is there a way to get rid of this warning? And, if it is something that can't be resolving isn't there a risk that something will break?

mribeiro avatar Oct 25 '18 09:10 mribeiro

I am also having problems using xml-js with angular 6. I am getting the same error:

ReferenceError: Buffer is not defined
    at Object.push../node_modules/xml-js/lib/json2xml.js.module.exports [as json2xml] (json2xml.js:4)

HugoJBello avatar Nov 15 '18 16:11 HugoJBello

Same for me, I use xmljs.js2xml in Angular 7 and got

WARNING in ./node_modules/sax/lib/sax.js
Module not found: Error: Can't resolve 'stream' in 'path\to\nodeModules\node_modules\sax\lib'

UPDATE:

I was able to "remove" the WARNING by changing in sax.js the require('stream') with require('readable-stream') is there any permanent solution to this issue?

ALGDB avatar Dec 04 '18 20:12 ALGDB

Hello, I just installed xml-js and I am getting this error in console... Is there any update in how to permanently fix it?

Using Angular 8.0

iMrLopez avatar Nov 17 '19 02:11 iMrLopez

Hello, I just installed xml-js and I am getting this error in console... Is there any update in how to permanently fix it?

Using Angular 8.0

See: https://stackoverflow.com/a/55788098/4604351

itPiligrim avatar Jan 09 '20 11:01 itPiligrim