[英]typescript can't find node_modules
Following on from TypeScript 101 QuickStart ( https://www.typescriptlang.org/docs/tutorial.html ) using Visual Studio 2015 and Node Tools for Visual Studio I tried importing 'winston' (after adding the npm module), but whatever path I use, Visual Studio says it can't find it. 从使用Visual Studio 2015和Visual Studio的Node Tools的TypeScript 101快速入门( https://www.typescriptlang.org/docs/tutorial.html )开始,我尝试导入“ winston”(添加npm模块之后),但是路径不限我使用了,Visual Studio说找不到。
How do I load external npm modules? 如何加载外部npm模块? (I'm using the CommonJs compile option).
(我正在使用CommonJs的编译选项)。
Here's a screenshot: Visual Studio Output 这是屏幕截图: Visual Studio输出
First, install 'typings': npm install typings --global
首先,安装“ typings”:
npm install typings --global
Then, from the command line (in the root of your project), use typings to install the '.d.ts' file for 'winston': 然后,从命令行(在项目的根目录中),使用键入内容为“ winston”安装“ .d.ts”文件:
typings install winston --source dt --save --global
The typings file will be added to your project in the typings/global/winston
folder. 打字文件将被添加到您的项目中的
typings/global/winston
文件夹中。 Now add the following to the top of your 'app.js' file: 现在,将以下内容添加到“ app.js”文件的顶部:
/// <reference path="typings/globals/winston/index.d.ts"/>
You can now use the winston logger like this: 您现在可以像这样使用Winston记录器:
var winston = require('winston');
winston.level = 'debug';
winston.debug('Debug messages are written to the console with the default logger.');
I added the 'fs-etxra' npm package to the project, then added the typings in the same way as above. 我向项目添加了“ fs-etxra” npm软件包,然后以与上述相同的方式添加了类型。 The resulting project can be seen in the following screenshot:
在以下屏幕截图中可以看到生成的项目:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.