#Convex Package.json "exports" in a Monorepo

21 messages · Page 1 of 1 (latest)

harsh spoke
#

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?

deft saffronBOT
#

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](https://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!
dense spoke
#

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

#

^ 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

harsh spoke
#

Hey @dense spoke 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.

dense spoke
#

could you send where you saw that in the docs?

harsh spoke
#

It’s not a typescript feature

dense spoke
#

😅 If you scroll up you clearly can see its for the package.json!

harsh spoke
#

Package.json is not a TS feature

#

It how you define package in a general for ESM, npm and JavaScript, not related to typescript

#

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.

dense spoke
#

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!

harsh spoke
#

Thank you @dense spoke 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! 🙏

karmic beacon
#

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.