Calen
Calen
CCConvex Community
Created by Calen on 1/17/2025 in #support-community
Error: Convex functions should not be imported in the browser.
My convex server looks like this:
'use node';
import { v } from 'convex/values';
import { action } from '../../_generated/server';
import { initProject } from '../../ai/codegen';

export const createProject = action({
args: {
prompt: v.string(),
model: v.string(),
},
handler: async (ctx, args) => {
const { prompt, model } = args;
const result = await initProject({
prompt,
model,
});
return result;
},
});
'use node';
import { v } from 'convex/values';
import { action } from '../../_generated/server';
import { initProject } from '../../ai/codegen';

export const createProject = action({
args: {
prompt: v.string(),
model: v.string(),
},
handler: async (ctx, args) => {
const { prompt, model } = args;
const result = await initProject({
prompt,
model,
});
return result;
},
});
I use it in react like so:
I use it in react like so:
import { useAction } from 'convex/react';
import { api } from '../../convex/_generated/api';
...

const initProject = useAction(api.actions.ai.actions.createProject);
import { useAction } from 'convex/react';
import { api } from '../../convex/_generated/api';
...

const initProject = useAction(api.actions.ai.actions.createProject);
When i start the react app i get this error:
throw new Error("Convex functions should not be imported in the browser.");
throw new Error("Convex functions should not be imported in the browser.");
Why do I get this and how can I fix it
29 replies