atproto
atproto copied to clipboard
@atproto/api package imports throwing in SSR apps
@atproto/api
currently does not work natively with SSR apps when served server-side (e.g. built with sveltekit and served with Vite). You'll get the error exports is not defined at ajv-formats/dist/index.js:4:23
. I believe this has to do with ajv-formats
being a CommonJS module.
The api can only be imported in the client-side when doing it like const api = await import("@atproto/api");
in the browser side (i.e. inside an onMount()
) which adds big initial page load times since it's loaded into the browser session separately rather than being a part of the vite-generated js chunks.
Javascript module issues amiright? Yeah I remember having some issues with sveltekit & CommonJS modules in the past.
Which code are you actually pulling in here? dist/
?
Hoenstly, none of our libraries are quite ready to be building with yet (although we're stoked to have people playing with them!) - we'll be doing a DX pass on all of these, cleaning up, publishing & hopefully sorting out these module/build issues before long.
@dholms This happens when importing either from dist
or src
.
I'll keep playing with the packages and will report if I find anything else!
@dholms it seems that all you might need to do is add "type": "module"
to package.json
You guys are already using the export
that modules use, but the packages aren't registered as a module.
Probably duplicates: https://github.com/bluesky-social/atproto/issues/623 https://github.com/bluesky-social/atproto/issues/781 https://github.com/bluesky-social/atproto/issues/910
Would be happy to try to contribute this change!
People building sites with Astro like a couple of us are in this discussion don't really have a viable workaround https://github.com/bluesky-social/atproto/discussions/1153