qwe asd qwe asd -4 years ago 167
TypeScript Question

Using npm modules in Typescript

I would like to use npm module in Typescript project but there is no typings or tsd for this module. When I try use

import Module from 'module'
I had an error :
Cannot find module 'module'.
Is there way to fix it?


"compilerOptions": {
"target": "ES5",
"moduleResolution": "node",
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": true,
"experimentalDecorators": true,
"sourceMap": true,
"sourceRoot": "src",
"outDir": "bld"
"exclude": [

Answer Source

I assume your question is related to importing the module

import Module from 'module'

And not exporting it as you stated. If this is the case your can fall back to plain javascript and require module like this:

var Module = require('module');


Verify that in tsconfig.json you have the following lines in compiler options:

"compilerOptions": { 
    "moduleResolution": "node",
    "module": "commonjs"

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download