How to import xml2js in an angular2 app using angular-cli with webpack

不问归期 提交于 2019-12-07 09:44:32

问题


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';

i got the message:

Cannot find module 'xml2js'.)

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

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

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


回答1:


You need to install the type definitions for xml2js

NPM:

npm install @types/xml2js --save-dev

YARN:

yarn add @types/xml2js -D


来源:https://stackoverflow.com/questions/42891332/how-to-import-xml2js-in-an-angular2-app-using-angular-cli-with-webpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!