honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
18.53k stars 521 forks source link

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

Closed bkerin closed 4 days ago

bkerin commented 1 month ago

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/hono@4.5.3"). 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/hono@4.5.3/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/hono@4.5.3/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

nakasyou commented 1 month ago

Hi @bkerin

Try to change deno.json:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxFragmentFactory": "Fragment",
    "jsxImportSource": "@hono/hono/jsx"
  }
}
yusukebe commented 4 days ago

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