如何在webpack中使用angular-cli在angular2应用程序中导入xml2js [英] How to import xml2js in an angular2 app using angular-cli with webpack

查看:132
本文介绍了如何在webpack中使用angular-cli在angular2应用程序中导入xml2js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于使用angular2的应用程序(来自webpack的angular-cli),我需要从soap Web服务中使用xml中的一些数据.我使用的angular-cli本身提供了用于将xml解析为json的库xml2js我尝试使用以下语法在我的组件中使用此库:

For an application using angular2 (from angular-cli with webpack), i need to consume some data in xml from a soap web service.The angular-cli that i use provide natively the library xml2js for parsing xml to json but when i try to use this library in my component using the following syntax:

import {Parser} from 'xml2js';

我收到消息:

Cannot find module 'xml2js'.)

但是,此库确实安装在node_modules文件上.

However, this library is really installed on the node_modules file.

我到处搜索,但只找到了一些使用system.js配置的解决方案.

I searched everywhere but i only found some solutions with system.js config.

有人知道如何使用webpack在angular2中使用此库吗?

Does anyone know how to use this library in an angular2 using webpack?

推荐答案

您需要安装xml2js的类型定义

You need to install the type definitions for xml2js

NPM:

npm install @types/xml2js --save-dev

纱:

yarn add @types/xml2js -D

这篇关于如何在webpack中使用angular-cli在angular2应用程序中导入xml2js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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