0

I am trying to import xml2js module , but facing 404 error saying xml2js not found

import xml2js from 'xml2js';

How to import JavaScript modules present in node_modules directory in TypeScript?

James Monger
  • 10,181
  • 7
  • 62
  • 98
  • If you are using Angular-Cli you can check answer : https://stackoverflow.com/questions/42410531/xml-data-parsing-in-angular-2/45067926#45067926 – dpetrini Jul 12 '17 at 21:57

2 Answers2

0

You need to add a reference path

/// <reference path="node_modules/xml2jse/xml2js.d.ts" />
import xml2js = require("xml2js");

Remember you need to have a typescript module of xml2js

tsd install xml2js
Thalaivar
  • 23,282
  • 5
  • 60
  • 71
0

I think you need to install or at least write a Module declaration. Here is the declaration file on definitely typed: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/xml2js/xml2js.d.ts

You can install these module declarations with typings. https://github.com/typings/typings

On declaration files: https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html

You can also write your own module declarations but I recommend to look first in the registries. TypeScript will not understand any module without a declaration file.

Hope that helps ;)

meandmax
  • 114
  • 6