5

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?

Sedo
  • 63
  • 1
  • 6

2 Answers2

10

You need to install the type definitions for xml2js

NPM:

npm install @types/xml2js --save-dev

YARN:

yarn add @types/xml2js -D
J J B
  • 8,540
  • 1
  • 28
  • 42
  • @AndreiDiaconescu could you expand on why you believe this doesn't work anymore? This is only installing the types for that package. – J J B Aug 10 '18 at 13:57
  • 2
    You have to run `npm install --save stream timers` to make it work with Angular 6 – Iter Ator Aug 31 '18 at 08:32
0

I would add this to JJB's answer. Got the same problem. I solved it by installing theses 3 dependencies: sax/ xmlbuilder/timers

- npm install @types/xml2js --save

  • npm install --save @types/sax
  • npm install --save @types/xmlbuilder
  • npm install --save @types/timers

Or

  • npm install xml2js --save
  • npm install --save sax
  • npm install --save xmlbuilder
  • npm install --save timers

see:

Regards