简体   繁体   English

打字稿找不到node_modules

[英]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: 在以下屏幕截图中可以看到生成的项目:

Visual Studio Screenshot Visual Studio屏幕截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 节点找不到模块,但它存在于node_modules中? - Node can't find module but it exists in node_modules? 节点找不到父node_modules文件夹中存在的模块 - node can't find modules that exists in parent node_modules folder 我无法从node.js中的打字稿中导入node_modules - I can't import node_modules from typescript in node.js 找不到node_modules路径 - node_modules path can't be found 如何解析打字稿导入以在node_modules中找到库? - How are typescript imports resolved to find libraries in node_modules? NodeJS找不到bower_components,但可以在Windows上找到node_modules - NodeJS can't find bower_components but can find node_modules on windows NOde.js / Express App找不到某些node_modules - NOde.js/Express App can't find some node_modules 我可以让 TypeScript 包含用于转译的 node_modules 吗? - Can I make TypeScript include node_modules for transpilation? NestJs 找不到模块 platform-express,即使它安装在 node_modules 中 - NestJs can't find module platform-express even though it's installed in node_modules 找不到模块:错误:无法解析&#39;/ workspace / node_modules / pace / node_modules / charm&#39;中的&#39;tty&#39; - Module not found: Error: Can't resolve 'tty' in '/workspace/node_modules/pace/node_modules/charm'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM