Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Neeraj-swarnkar opened this issue Feb 11, 2022 · 3 comments

Comments

@Neeraj-swarnkar
Copy link

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.

@Tandashi
Copy link

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.

@vub
Copy link
Contributor

vub commented Aug 2, 2022

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

import * as DetectRTC from 'detectrtc';

@ORN-Fox
Copy link

ORN-Fox commented Nov 22, 2022

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",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants