【发布时间】:2017-03-19 09:13:13
【问题描述】:
我得到 File node_modules/@types/webrtc/index.d.ts is not a module 使用此代码:
import * as webrtc from "webrtc";
const peerConnection1 = new RTCPeerConnection();
我已经使用npm i @types/webrtc --save-dev 安装了类型。将鼠标悬停在 const peerConnection1 = new RTCPeerConnection(); 中的 RTCPeerConnection 上会在 Visual Studio Code 中显示类型注释,因此至少代码编辑器可以看到这些类型。运行 tsc(或 webpack 和 ts-loader)失败并出现错误。
我尝试过npm i webrtc --save 尝试解决这个问题,但它并没有改变任何东西,我真的只想要打字,WebRTC 就在浏览器中,我不需要一个包。 (支持一边。)
index.d.ts 文件确实不是一个模块,它只是引用了另外两个带有接口的文件。所以我想删除import * as webrtc from "webrtc";,希望tsc 以某种方式仍然可以看到打字。 (但这是不可能的,因为我在 TypeScript 配置文件中排除了node_modules。)当我这样做时,RTCPeerConnection 不再被识别。
添加/// <reference src="node_modules/@types/webrtc/" /> 没有帮助,tsc 表示引用指令语法无效。
您可以查看具有最少复制here on GitLab 的存储库。我对 TypeScript 类型的获取不太精通,所以如果我做错了,请原谅我的无知。
【问题讨论】:
标签: typescript typescript-typings