6

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?

2 Answers 2

10

You need to install the type definitions for xml2js

NPM:

npm install @types/xml2js --save-dev

YARN:

yarn add @types/xml2js -D
Sign up to request clarification or add additional context in comments.

2 Comments

@AndreiDiaconescu could you expand on why you believe this doesn't work anymore? This is only installing the types for that package.
You have to run npm install --save stream timers to make it work with Angular 6
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.