xml-js
xml-js copied to clipboard
Can't resolve 'stream'
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'
Yes, it's a known issue. Please read #54
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 ?
I think no. IMO there must be an error in your code. What's inside your app.component.ts
, in registerUser
method?
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
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})); }
Please don't delete your comments. It can help others with similar issues
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
Is there another way when it works with Angular?
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}))
}
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'
Same here!
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?
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)
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?
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
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