danielyogel
danielyogel21h ago

Convex Package.json "exports" in a Monorepo

Every package in a monorepo should specify "exports" in Package.json - so other packages in the monorepo could consume the relevant parts of it. As well as implying if the package should be consumed as built JS files or source source TS code and compiled by the consumer. I am trying to understand what should I export from a Convex package. I've looked in the https://github.com/get-convex/turbo-expo-nextjs-clerk-convex-monorepo example, and the Convex package does not export anything. What is the best practice regarding this?
14 Replies
Convex Bot
Convex Bot21h ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
Sara
Sara21h ago
when you say export, do you mean in the ts config? If so you might need to add that into the directory itself, else you would need to just use something like @repo/convex and stuff like that
Sara
Sara21h ago
^ something like this, you name the package in the directory the thing you want that directory to be specifed as, at least that's what turbo pack suggests
Sara
Sara21h ago
GitHub
turbo-expo-nextjs-clerk-convex-monorepo/packages/backend/package.js...
Monorepo template with Turborepo, Next.js, Expo, Clerk, Convex - get-convex/turbo-expo-nextjs-clerk-convex-monorepo
danielyogel
danielyogelOP18h ago
Hey @Sara your example does specify an “exports” field as turbo suggest, but it exports the while folder, generated and also ungenerated code, which I guess is not optimal. The get-convex temple has nothing in the exports field… which is strange.
Sara
Sara18h ago
turbo does not suggest exports could you send where you saw that in the docs? https://turborepo.com/docs/crafting-your-repository/structuring-a-repository#exports this is just a typescript feature, and it is not mandatory, if you find anything that needs to be fixed or see flimsy output in your repository, feel free to update that, I believe by default everything is exported
danielyogel
danielyogelOP18h ago
It’s not a typescript feature
Sara
Sara18h ago
😅 If you scroll up you clearly can see its for the package.json!
danielyogel
danielyogelOP18h ago
Package.json is not a TS feature It how you define package in a general for ESM, npm and JavaScript, not related to typescript Also check here https://turborepo.com/docs/crafting-your-repository/creating-an-internal-package#add-a-packagejson Only the types field is related specifically to types “exports: Defines multiple entrypoints for the package so it can be used in other packages (import { add } from '@repo/math/add').” every monorepo example I’ve ever seen specified this.
Sara
Sara18h ago
I don't know how is this argument related to convex anymore, and I'm not trying to argue here, having released packages before and built projects with it, I've never had an error telling me its a "Must". it's up to you to decide how you want to work with it and update it, the reposoitory is "up for grabs" if you want to update it!
danielyogel
danielyogelOP17h ago
Thank you @Sara for your point of view ✌️haven’t said an error would be thrown if not specified, just that all monorepos I’ve seen specify the exports field, because this way you can narrow what is exposed from a repo, but more importantly it controls if the repo should be used as built JS code OR source TS code (which is a big difference, both valid in different situations). Anyway, from looking at more examples it looks like only the generated code is used in the clients, so the field of exports in a monorepo would better be the _generated folder. Would love to hear from more ppl about this subject. Thanks! 🙏
erquhart
erquhart17h ago
Yeah just generated code is used in the client, you could write some exports for that if you wanted, but exports aren't a requirement. Path based imports like that template has are equally effective. But yeah, if you prefer exports you can add 'em. To answer your question explicitly, I believe the only export you would use would be from the _generated/api directory.
danielyogel
danielyogelOP17h ago
Cool, thanks!

Did you find this page helpful?