Error: Convex functions should not be imported in the browser.
My convex server looks like this:
When i start the react app i get this error:
Why do I get this and how can I fix it
18 Replies
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!
That all looks right. Are there any other imports to stuff in your
convex
directory (aside from _generated/api
?
Does the error show a stack trace?I don't think theres any more relevant stuff in the
convex
dir.
I am calling it in a component of https://github.com/expo/snack (website/src/client)GitHub
GitHub - expo/snack: Expo Snack lets you run Expo in the browser.
Expo Snack lets you run Expo in the browser. Contribute to expo/snack development by creating an account on GitHub.
This is the stacktrace
This error is there to say "hey, careful, it looks like you're shipping Convex functions (your potentially secret backend) with your client"
so somewhere you're importing code that includes a
const list = query(...)
in a file that runs in the browser
hm I don't see the error you mentioned here though
so maybe that's not what's happeningIm confused.
If my client is client site rendered I cannnot call:
?
Where doyou see this error? I think this error isn't actually happening
These logs indicate a different issue
If my client is client site rendered I cannnot call:No that's fine
So this is the whole file:
Could you show a screenshot of this error? I'm wondering if you saw this error in these logs and then assumed the error was being thrown, but actually it's not being thrown
that's just a line of source code
When i comment out line 28:
it works just fine, if i uncomment it i get this error
Your file is fine
What is "this error," what is the error?
The error I see in the logs you posted is "Failed to compile"
ah i see what you mean now
confusing because that line is visible, but the highlighted line is a couple lines off
mhm i will try to figure it out, thanks a lot and sorry for the confusion
it does seem like it's to do with this Convex code though
looks like it's about the
?
in thereyeah convex uses react 18?
the expo snack requires react 16.x.x
so whatever your bunder setup is, it's having trouble with optional chaining
stuff like
const name = options?.name
https://github.com/expo/snack/pull/302/ looks like it might be relevant here -- some issue with the custom packager
expo/snack
uses
But also, Convex definitely works smoothly with Expo Go (https://docs.expo.dev/develop/tools/#expo-go) including the web view, in case you're open to using that instead of snacksGitHub
[snackager] correct output with package type: module by mmomtchev ·...
Why
Refs: #299
Refs: microsoft/rnx-kit#142
The Metro Babel preset does not produce correct output
for packages containing "type": "module" unless
the disableImpo...
Expo Documentation
Tools for development
An overview of Expo tools and websites that will help you during various aspects of your project-building journey.