typescript 打字稿 - 在 Visual Studio Code 上找不到模块“http”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38434864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:40:00  来源:igfitidea点击:

Typescript - Cannot find module 'http' on Visual Studio Code

typescriptnodesvisual-studio-code

提问by R3Tech

i'm using Visual Studio Code for NodeJS and Typescript development. If I'm writing this code:

我正在使用 Visual Studio Code 进行 NodeJS 和 Typescript 开发。如果我正在编写此代码:

import * as http from 'http'; 

The compile says error TS2307: Cannot find module 'http'.

编译说 error TS2307: Cannot find module 'http'.

How to handle this error?

如何处理这个错误?

Greetz

格雷茨

回答by Isolated

This worked for me:

这对我有用:

npm install @types/node --save

I realise it's been a while since the OP, however this is a more updated answer in case someone stumbles across this problem.

我意识到自 OP 以来已经有一段时间了,但是如果有人偶然发现这个问题,这是一个更新的答案。

回答by Andre Bossard

I have the same issues. It's similar to that: https://github.com/TypeStrong/ts-node/issues/216

我有同样的问题。它类似于:https: //github.com/TypeStrong/ts-node/issues/216

After installing the typings with:

安装类型后:

typings install dt~node --global --save

And then added this to my file:

然后将其添加到我的文件中:

///<reference path="../typings/globals/node/index.d.ts"/>

And suddenly it works.

突然它起作用了。