Next.js Discord

Discord Forum

Exporting inferred types from server code to client without importing server-only deps

Unanswered
Bar-tailed Godwit posted this in #help-forum
Open in Discord
Bar-tailed GodwitOP
I’m running into a problem with my monorepo setup.

Inside my ai package I have all the project’s tools defined and exported like this:

import { InferUITools } from "ai"
import { deepResearch } from "./deepResearch"
import { flashcardGeneratorTool } from "./flashcard-generator"
import { graphTool } from "./graph"
import { plotTool } from "./plotTool"
import { quizGeneratorTool } from "./quiz-generator"

const TOOLS = {
  graphTool,
  quizGeneratorTool: quizGeneratorTool(),
  flashcardGeneratorTool: flashcardGeneratorTool(),
  deepResearch: deepResearch(),
  plotTool,
} as const

export type ToolTypes = InferUITools<typeof TOOLS>


The problem: when I import ToolTypes in my frontend app, I get a bunch of build errors.
This happens because the tools themselves depend on server-only packages, which aren’t compatible with the client build.

What’s a good way to structure this so I can still infer the types (ToolTypes) in the frontend without importing server-only code?

0 Replies