When I try to use the code below, I encounter the error File node_modules/@types/webrtc/index.d.ts is not a module:
import * as webrtc from "webrtc";
const peerConnection1 = new RTCPeerConnection();
I have installed the typings using npm i @types/webrtc --save-dev
. Although Visual Studio Code shows type annotations when hovering over RTCPeerConnection
, running tsc
or webpack
with ts-loader
throws an error.
In an attempt to solve this issue, I mistakenly tried npm i webrtc --save
, but it made no difference. My main goal was to acquire the typings, as WebRTC is available in the browser without needing a package (aside from support considerations).
The index.d.ts
file simply references two other files containing interfaces. I thought of removing
import * as webrtc from "webrtc";
and hoping that TypeScript would still recognize the typings in some way. However, since I exclude node_modules
in my TypeScript config file, this approach is not feasible and results in RTCPeerConnection
being unrecognized.
Even adding
/// <reference src="node_modules/@types/webrtc/" />
did not resolve the issue, as tsc
outputs Invalid reference directive syntax.
You can find a repository showcasing a simple reproduction of this problem on GitLab here. As I am not very familiar with acquiring TypeScript typings, I apologize for any mistakes I may have made along the way.