can i add lemmy-api-client to my webpage (yes. me again.)

hello. I recently asked here for help with Lemmy HTTP API and someone said "why don't you use lemmy-js-client?". i tried to add it and...

first i searched the internet about this library and it turns out that it is an npm library... (I have github pages) i searched different variations of the library and found a cdn version of it. i tried to add it. it was a hell of a torture.... i added it the way I add cdn libraries, nothing. i searched all over the internet, but found null. i even asked chatgpt! to no avail. the library (and everything I tried to get out of it) turned into undefined!

what am I supposed to do? this is cdn version what i tried to add
if u want here is source code

8 points · 9 comments · view on lemmy.world

9 Comments

brian@programming.dev · 2 pts · 1y (2 replies)

try opening that cdn link you sent in a browser. it'll open a directory listing for the package. you can see some examples of what urls to use on the main jsdelivr page.

I imagine the url you want is probably something like https://cdn.jsdelivr.net/npm/lemmy-js-client@0.20.0-image-api-rework.8/dist/index.js (note the extra path on the end and also a specific pinned version instead of latest so new versions don't break things)

okelote360@lemmy.world · 0 pts · 1y
okelote360@lemmy.world · 0 pts · 1y

i already use what urls!

Kissaki@programming.dev · 2 pts · 1y (5 replies)

Maybe include your "add it" and "the library turned into undefined" code as a minimum example?

So people can actually check your assumptions and actions and match it against the lib.

okelote360@lemmy.world · 0 pts · 1y (4 replies)
Kissaki@programming.dev · 1 pts · 1y (3 replies)

That js file certainly doesn't look like a normal module to me that I would expect when importing a module.

But I'm not too familiar with the JS ecosystem to the point where I know what that dynamic Object.defineProperty(exports, "__esModule" magic does or how it's supposed to be used.

But I can see why the import would result in undefined.


With my first search of LemmyHttp I land on https://join-lemmy.org/api/classes/LemmyHttp.html, which says Defined in src/http.ts:153. Have you considered importing http.js? Looking at the http.js on the CDN I can at least see the LemmyHttp class type you seem to try to import.

okelote360@lemmy.world · 0 pts · 1y (1 reply)

exports not defined...

Kissaki@programming.dev · 1 pts · 1y

given how dynamic creation it looks maybe it has to be executed/included rather than imported and then the class is available?

With all that magic, and looking at https://join-lemmy.org/api/index.html if you're not using pnpm I would give up on that lib.

okelote360@lemmy.world · 0 pts · 1y

hmmm... okay!