why I am getting error: Convex functions should not be imported in the browser
I don’t understand what I have to pay attention to to fix this mistake

3 Replies
It sounds like you're importing the function directly rather than through the
api
objectI checked, no, I import all functions through the api object
Based on this error message @antonsadovskiy it looks like
window
is defined when you run your convex functions. You might be using a library that defines it?
As a workaround you could temporarily include code like
in the file where your Convex functions are defined above their definitions
I'm curious about who is setting window, could be a polyfill — you might try console.log(window);
to see
We can make this check more cautious and allow window to exist if you're in the Convex environment — the point of the check is to prevent convex functions from being defined in a browser, because that could mean you're shipping potentially secret code in your browser bundle.
We'll change this to more precisely detect a browser environment, would love to know what window
is for you @antonsadovskiy so that we can be sure we're fixing this for you.
Thanks for your help, for others reading the issue was something like
because defining global.window
makes Convex think that the functions are in the browser, which could mean a security issue. But in this case this is fine! So we'll fix this, it's a false alarm from Convex.