Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@atproto/api package imports throwing in SSR apps #330

Open
deanpress opened this issue Nov 9, 2022 · 4 comments
Open

@atproto/api package imports throwing in SSR apps #330

deanpress opened this issue Nov 9, 2022 · 4 comments

Comments

@deanpress
Copy link
Contributor

deanpress commented Nov 9, 2022

@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.

@deanpress deanpress changed the title api package imports throwing in SSR apps @atproto/api package imports throwing in SSR apps Nov 9, 2022
@dholms
Copy link
Collaborator

dholms commented Nov 9, 2022

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.

@deanpress
Copy link
Contributor Author

deanpress commented Nov 13, 2022

@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!

@mikuhl-dev
Copy link

mikuhl-dev commented May 5, 2023

@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:
#623
#781
#910

@jacklorusso
Copy link

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 #1153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants