eclipse-zenoh / zenoh-ts

TypeScript Interface to the Zenoh Protocol.
http://zenoh.io
6 stars 4 forks source link

key_expr module not found with deno #4

Closed romainreignier closed 21 hours ago

romainreignier commented 2 weeks ago

I wanted to try this new zenoh-ts and I have written a simple deno application but when I run deno run main.ts, I have this error:

error: [ERR_MODULE_NOT_FOUND] Cannot find module 'file:///home/rre/.cache/deno/npm/npm.pkg.github.com/@eclipse-zenoh/zenoh-ts/0.0.9/dist/key_expr' imported from 'file:///home/rre/.cache/deno/npm/npm.pkg.github.com/@eclipse-zenoh/zenoh-ts/0.0.9/dist/index.js'

I am NOT a typescript developer so it might be an issue on my side or a compatibility issue with the NPM package format expected by deno.

Steps to reproduce

//npm.pkg.github.com/:_authToken=<your_token>
@eclipse-zenoh:registry=https://npm.pkg.github.com/
import { sleep } from "https://deno.land/x/sleep/mod.ts";
import {
  Session,
  Config,
  Sample,
  Subscriber,
  deserialize_string,
} from "npm:@eclipse-zenoh/zenoh-ts";

if (import.meta.main) {
  const session = await Session.open(Config.new("ws/127.0.0.1:10000"));
  const callback = async function (sample: Sample): Promise<void> {
    console.log!(
      ">> [Subscriber] Received " +
        sample.kind() +
        " ('" +
        sample.keyexpr() +
        "': '" +
        sample.payload().deserialize(deserialize_string) +
        "')",
    );
  };

  let callback_subscriber: Subscriber = await session.declare_subscriber(
    "demo/pub",
    callback,
  );

  await sleep(1000 * 3);
  callback_subscriber.undeclare();
}

As a side note, the version 0.0.8 mentioned in the README is not present in the Github NPM repo, only the version 0.0.9.

romainreignier commented 2 weeks ago

I have tested the same kind of code in the browser, based on your example and it works (package.json and yarn install). So it might be an incompatibility with deno.

Charles-Schleich commented 1 week ago

Hi romainreignier Thanks for the report !

So this looks like an issue with how Typescript transpiles into Javascript, not appending .js to the file extension in the js source in /dist. Browsers seem to handle this without the extension, looks like deno doesn't. It looks like including the .js in typescript source shouldn't effect the compilation other than fixing imports for deno.

I will test this out and open a PR to get this to work in Deno as well. Deno looks like it might be a better bet to getting the Typescript bindings working on the server than Node.js.

Charles-Schleich commented 21 hours ago

Support for Deno has been added in https://github.com/eclipse-zenoh/zenoh-ts/pull/22.