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?
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?
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
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 ;)