DenoDDeno
Powered by
RobWR
Denoβ€’6mo agoβ€’
3 replies
RobW

How to integrate a legacy JavaScript project with Deno TypeScript.

I'm attempting to use this package (https://github.com/nodertc/stun) that supports the STUN protocol, which is used by VoIP systems to handle NATs and firewalls. I can use it just fine as a JavaScript package under Node, but I am tearing my hair out trying to figure out how to import all the dependencies into my Deno project. (First time I've tried to use Deno, by the way.).

There are no TypeScript type annotations for this particular module. I've moved all code that interfaces with the legacy package into is own module, like this:

import stun from 'stun';

export async function getPublicIPAddressViaStun(url) {
try {
const result = await stun.request(url);
const ipAddress = result.getXorAddress().address;
return [ipAddress, undefined]
}
catch (error) {
return [undefined, error.message];
}
}

And I can use it from my main code thus:

import { getPublicIPAddressViaStun } from "./stun.js";

const [ipAddress, error] = await getPublicIPAddressViaStun('stun.l.google.com:19302');
if (ipAddress) {
console.log('Your ip address is', ipAddress);
} else {
console.error(error);
}

Now, when I try to use similar code in my Deno project, I get an error message when Deno tries to load dependencies of the STUN package, buried in a lib file:

error: Uncaught (in promise) Error: Cannot find module 'message/request'
Require stack:
- /Users/rwelbourn/Library/Caches/deno/npm/registry.npmjs.org/stun/2.1.0/src/index.js
- /Users/rwelbourn/Library/Caches/deno/npm/registry.npmjs.org/stun/2.1.0/src/index.js
...

Can anyone think of a way around this?
GitHub
GitHub - nodertc/stun: Low-level Session Traversal Utilities for NA...
Low-level Session Traversal Utilities for NAT (STUN) client and server - nodertc/stun
GitHub - nodertc/stun: Low-level Session Traversal Utilities for NA...
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to transpile typescript to javascript?
jsoldiJjsoldi / help
17mo ago
Can I transpile TypeScript Code to JavaScript Code with Deno like Bun
XiΓ  πŸ‡΅πŸ‡ΈXXiΓ  πŸ‡΅πŸ‡Έ / help
2y ago
Testing a Deno project with Vitest
foobarFfoobar / help
3mo ago
Deno + TypeScript
TimTTim / help
2y ago