#How can I load Trigger.dev tasks from two different apps in my monorepo?

1 messages · Page 1 of 1 (latest)

umbral perch
#

Hi folks, I’m trying to load my Trigger.dev tasks from two different apps in my monorepo.

The path ./core/jobs/trigger is relative to the app where my trigger.config.ts file is located (/apps/web). The second path ../api/src/trigger points to another app in the monorepo, which also contains tasks that I want to reuse.

I know the best approach here would probably be to create a separate package just for the tasks, but that’s not possible at the moment. The problem is that, even though I’m exporting tasks inside ../api/src/trigger, Trigger.dev throws the following error:

Error: No tasks exported from your trigger files

Here’s my config:

export default defineConfig({
  enableConsoleLogging: true,
  project: "<ref>",
  logLevel: "log",
  maxDuration,
  retries: {
    enabledInDev: true,
    default: {
      maxAttempts: 3,
      minTimeoutInMs: 1000,
      maxTimeoutInMs: 10000,
      factor: 2,
    },
  },
  dirs: ["./core/jobs/trigger", "../api/src/trigger"], // the api path reference another app in my monorepo
  instrumentations: [new OpenAIInstrumentation()],
  build: {
    external: ["jsdom"],
    extensions: [
      additionalFiles({ files: ["data/countries.json"] }),
      syncVercelEnvVars(),
      prismaExtension({
        schema: "../../packages/db/prisma/schema.prisma",
        clientGenerator: "client",
        version: "6.13.0",
      }),
    ],
  },
});

And here’s one of my tasks inside the api app:

export const createMeterEventTask = schemaTask({...});

Has anyone faced this before? Is there a way to make Trigger.dev recognize tasks from another app in the monorepo, or is the only solution really to move them into a shared package?

mighty badgeBOT
#

Hi @umbral perch. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the official Trigger.dev documentation, the recommended and fully supported way to share tasks between multiple apps in a monorepo is to create a dedicated shared tasks package (e.g., @repo/tasks). This approach is well-documented and ensures that tasks can be imported and used across different apps without issues. The docs provide clear guidance and working examples for this setup, including how to structure your monorepo, export tasks, and configure your trigger.config.ts files for both the tasks package and consuming apps. This is the approach used in their example projects and is explicitly recommended for sharing tasks across apps Monorepo setup.

When it comes to loading tasks from multiple directories using the dirs option in trigger.config.ts, the documentation states that you can specify multiple directories, and Trigger.dev will search for tasks in those locations Config file: dirs. However, the documentation and examples only show this being used within a single app or package context, not across app boundaries in a monorepo.

There is no explicit documentation or example confirming that referencing a directory from another app (e.g., ../api/src/trigger) in the dirs array is supported or will work reliably. The error you are seeing (“No tasks exported from your trigger files”) suggests that Trigger.dev is not able to detect or load the tasks from the external app directory, which aligns with the lack of documentation for this use case.

#

Summary:

  • The only officially supported and documented way to share tasks between apps in a monorepo is to move them into a shared package.
  • Referencing another app’s directory directly in the dirs array is not documented as supported, and your error suggests it does not work.
  • If restructuring into a shared package is not possible right now, there is no documented workaround in the knowledge sources.

Recommendation:
If you need to share tasks, the best path forward is to create a shared tasks package as described in the docs Monorepo setup. If that’s not possible, you may need to duplicate the tasks for now, as there is no documented way to load tasks from another app’s directory.

If you want to see a working example of the shared package approach, check out the turborepo-prisma-tasks-package example referenced in the docs.

I'm sorry, but the knowledge sources do not contain information about supporting cross-app task loading via the dirs option, and the only documented solution is to use a shared package.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: