bigskysoftware / bigskysoftware/htmx

ESM typings mismatch (Deno)

Open
#3,453 7 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

The docs say we should use `window.htmx = require('htmx.org')`. But that's CJS. What should I use for ESM?

I'm using esbuild with the npm htmx package.

I tried `import htmx from "htmx.org"`. Guess the type of `htmx`: it's a module. But the actual runtime value is the library itself.
I should be able to write `htmx.onLoad`, but my LSP suggests `htmx.default.onLoad` instead.

For now, I'm doing this:
```ts
import htmx from "htmx.org";
import type HTMX from "htmx.org";
declare namespace globalThis {
let htmx: typeof HTMX.default;
}
globalThis.htmx = htmx as unknown as typeof HTMX.default;
(htmx as unknown as typeof htmx.default).config.methodsThatUseUrlParams.length = 0
import("htmx-ext-debug");
```

What I expect is this:
```ts
import htmx from "htmx.org";
htmx.config.methodsThatUseUrlParams.length = 0
globalThis.htmx = htmx;
import("htmx-ext-debug");
```

> [!NOTE]
> The plugins have bad ESM support too, and they require exposing `htmx` globally to use them.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.