使用Visual Studio 2015和Visual Studio的Node Tools从TypeScript 101 QuickStart(https://www.typescriptlang.org/docs/tutorial.html)开始,我尝试导入'winston'(在添加npm模块之后),但无论我使用什么路径,Visual Studio都说它找不到它。
如何加载外部npm模块? (我正在使用CommonJs编译选项)。
这是一个截图: Visual Studio Output
答案 0 :(得分:0)
首先,安装' typings':npm install typings --global
然后,从命令行(在项目的根目录中),使用typings安装' .d.ts'文件为' winston':
typings install winston --source dt --save --global
将打包文件添加到typings/global/winston
文件夹中的项目中。现在将以下内容添加到您的app.js'的顶部。文件:
/// <reference path="typings/globals/winston/index.d.ts"/>
您现在可以像这样使用winston记录器:
var winston = require('winston');
winston.level = 'debug';
winston.debug('Debug messages are written to the console with the default logger.');
我添加了&#39; fs-etxra&#39; npm包到项目,然后以与上面相同的方式添加类型。生成的项目可以在以下屏幕截图中看到: