从使用Visual Studio 2015和Node Tools for Visual Studio的TypeScript 101快速入门(https://www.typescriptlang.org/docs/tutorial.html)开始,我尝试导入“ winston”(在添加npm模块之后),但是路径如何我使用,Visual Studio说找不到。
如何加载外部npm模块?(我正在使用CommonJs的编译选项)。
这是屏幕截图:Visual Studio输出
首先,安装“类型”: npm install typings --global
然后,从命令行(在项目的根目录中),使用键入内容为“ winston”安装“ .d.ts”文件:
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.');
我向项目添加了“ fs-etxra” npm软件包,然后以与上述相同的方式添加了类型。在以下屏幕截图中可以看到生成的项目:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句