soheilpro soheilpro - 2 months ago 19
Node.js Question

Importing Node modules in TypeScript

How can I import Node modules which reside in the node_modules folder in TypeScript?

I get an error message (The name ''async'' does not exist in the current scope) when I try to compile the following piece of TypeScript code:

// Converted from: var async = require('async');
import async = module('async');

Answer Source

You need to create a definition file and include this:

module "async" {}

then add a reference to this definition file in your TypeScript code

///<reference path='definition-file.d.ts' />

import async = module('async');