Angular 6中的xml2js:无法解析“流"和“计时器" [英] xml2js in Angular 6: Can't resolve 'stream' and 'timers'

查看:190
本文介绍了Angular 6中的xml2js:无法解析“流"和“计时器"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解析从服务器检索到的xml数据.不幸的是HttpClient不支持xml,仅支持json,因此我安装了包xml2js:

I would like to parse xml data, retrieved from the server. Unfortunately HttpClient does not support xml, only json, therefore I installed the package xml2js:

npm install xml2js --save
npm install @types/xml2js --save-dev

然后我尝试像这样使用它:

Then I try to use it like this:

import {Parser} from 'xml2js';

Parser.parseString(xml_str, function (err, result) {
    console.dir(result);
});

如果运行它,我会收到以下两个错误:

I get these two errors if I run it:

WARNING in ./node_modules/xml2js/node_modules/sax/lib/sax.js
Module not found: Error: Can't resolve 'stream' in 'C:\projects\app\node_modules\xml2js\node_modules\sax\lib'

ERROR in ./node_modules/xml2js/lib/parser.js
Module not found: Error: Can't resolve 'timers' in 'C:\projects\app\node_modules\xml2js\lib'

我还没有找到解决此问题的任何方法,也许这仅仅是Angular6问题.有什么办法可以在Angular6中解析xml?

I haven't found any solutions to this problem, maybe it is an Angular6 issue only. Is there any way, to parse xml in Angular6?

推荐答案

您将必须安装这些依赖项.不幸的是,它没有得到很好的记录.

You’ll have to install those dependencies. It’s unfortunately not well documented.

npm install --save stream timers

这篇关于Angular 6中的xml2js:无法解析“流"和“计时器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆