DetectRTC icon indicating copy to clipboard operation
DetectRTC copied to clipboard

`import DetectRTC from 'detectrtc';` ES6 import giving error on typescript checking

Open Neeraj-swarnkar opened this issue 3 years ago • 3 comments

Hi @muaz-khan and all the contributor, I am use detectrtc with my typescript code.

When I try to use ES6 import, it's giving error on typescript checking. PFA for the same. import DetectRTC from 'detectrtc';

image

const DetectRTC = require('detectrtc'); This works fine,

Can you please fix this ? So we can use it with ES6 import. Thanks for the help.

Neeraj-swarnkar avatar Feb 11 '22 05:02 Neeraj-swarnkar

Since this issue hasn't had any updates lately and it doesn't look like it gets fixed anytime soon a quick workaround for this issue:

add a custom definitions file where you correct the errors:

// ...
declare namespace DetectRTC {
// ...
export function checkWebSocketsSupport(callback: () => void): any;
// ...
export function DetectLocalIPAddress(callback: (localIpAddress: string) => void): any;

And add this to your tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "detectrtc": ["definitions/detectrtc.d.ts"]
    }
  },
}

Here the definitions folder is a folder where your definition is located. Might be different for your setup.

This should enable you to still use ES6 imports.

Tandashi avatar Apr 29 '22 12:04 Tandashi

@Neeraj-swarnkar I see that the PR for this issue was merged. I was use wildcard for import DetectRTC

import * as DetectRTC from 'detectrtc';

vub avatar Aug 02 '22 14:08 vub

Hi, I had the problem too. I looked if the commit with the fix was available in the latest version currently (1.4.1) alas not. So I imported the master version which has the patch and here's how to fix it temporarily while waiting for a new version.

Change your import in the package.json to "detectrtc": "muaz-khan/DetectRTC#master",

ORN-Fox avatar Nov 22 '22 16:11 ORN-Fox