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?

1

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Can't we use javascript module?
If you are using webpack... stackoverflow.com/questions/33525027/…
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 ;)

Comments