Search code examples
xmlangularangular-clixml2js

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


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?


Solution

  • You need to install the type definitions for xml2js

    NPM:

    npm install @types/xml2js --save-dev
    

    YARN:

    yarn add @types/xml2js -D