hono icon indicating copy to clipboard operation
hono copied to clipboard

jsx directives don't work as advertised with deno and jsr

Open bkerin opened this issue 1 year ago • 1 comments

What version of Hono are you using?

4.5.3

What runtime/platform is your app running on?

Deno

What steps can reproduce the bug?

The docs at https://hono.dev/docs/guides/jsx suggest these pragmas:

/** @jsx jsx */
/** @jsxImportSource hono/jsx */

But they don't work with my setup (which consists of all import for hono using versioned jsr specifiers, e.g import { Hono } from "jsr:@hono/[email protected]"). Deno complains like for example this:

error: Relative import path "hono/jsx/jsx-runtime" not prefixed with / or ./ or ../
    at file:///home/bkerin/projects/test/web_server/deno_tsx_test.tsx:29:22

So I assume the problem is lack of versioning in the pragma, but using the full import import specifier doesn't work either:

/** @jsx jsx */
/** @jsxImportSource jsr:@hono/[email protected]/jsx */

results in:

error: pragma cannot be set when runtime is automatic at file:///home/bkerin/projects/test/web_server/deno_tsx_test.tsx:26:1

It turns out that leaving out the @jsx jsx pragma entirely and using the full import specifier like this:

/** @jsxImportSource jsr:@hono/[email protected]/jsx */

Seems to work, though I don't exactly know why. For docs on the way to get this working with deno it would be really nice to get the way to do it without compilerOptions, as one of the selling points on deno is the use of standard import and no need for extensive configuration files.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

bkerin avatar Jul 31 '24 21:07 bkerin

Hi @bkerin

Try to change deno.json:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxFragmentFactory": "Fragment",
    "jsxImportSource": "@hono/hono/jsx"
  }
}

nakasyou avatar Aug 04 '24 02:08 nakasyou

We can close this. If you still have the problem, feel free to reopen.

yusukebe avatar Sep 12 '24 06:09 yusukebe