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

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

问题描述

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

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天全站免登陆