我正在尝试使用xml2js作为TypeScript解析器,在一个Range2(RC1和TypeScript) use应用程序中。然而,我只得到一些错误,没有有效的解决方案。
以下是我一步一步地做的事情:
npm install xml2jstsd install xml2js安装了d.ts文件<script src="../node_modules/xml2js/lib/xml2js.js"></script>的脚本链接'xml2js': '../node_modules/xml2js'和将'xml2js': { defaultExtension: 'js' }添加到包中来配置'xml2js': { defaultExtension: 'js' }import {Parser} from 'xml2js';分析器var parser = new Parser(); var xml = "<root>Hello xml2js!</root>" parser.parseString(xml, function (err, result) { console.dir(result); });这是浏览器控制台在打开包含组件的网页时告诉我的:
module.js:440未明错误:找不到模块'sax‘
和
file:///C:/xxx/source/node_modules/xml2js net::ERR_FILE_NOT_FOUND
以及
file:///C:/xxx/source/node_modules/xml2js错误: index.html:17错误: XHR错误加载index.html:17 在(file:///C:/xxx/source/node_modules/zone.js/dist/zone.js:356:38) ZoneDelegate.invokeTask 在(file:///C:/xxx/source/node_modules/zone.js/dist/zone.js:256:48) Zone.runTask 在(file:///C:/xxx/source/node_modules/zone.js/dist/zone.js:423:34) XMLHttpRequest.ZoneTask.invoke 将file:///C:/xxx/source/node_modules/xml2js作为"xml2js“从file:///C:/xxx/source/frontend/angular/components/mycomponent/mycomponent.js加载时出错
"sax“通过npm安装在node_modules/xml2js/node_modules/sax中。我错过了安装外部库的什么?有没有一种“更好”的方法来使用外部JS库的角2& TypeScript?
发布于 2016-08-03 08:53:42
是的,有更好的方法。
您可以使用System.set('xml2js', System.newModule(require('xml2js')))在systemjs中加载本地xml2js模块。
https://stackoverflow.com/questions/38720871
复制相似问题