CalenC
Convex Community12mo ago
28 replies
Calen

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;
  },
});

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);


When i start the react app i get this error:
throw new Error("Convex functions should not be imported in the browser.");


Why do I get this and how can I fix it
Was this page helpful?