trigger.config.ts
file is used to configure your Trigger.dev project. It is a TypeScript file at the root of your project that exports a default configuration object. Here’s an example:
trigger.config.ts
- Specifying where your trigger tasks are located using the
dirs
option. - Setting the default retry settings.
- Configuring OpenTelemetry instrumentations.
- Customizing the build process.
- Adding global task lifecycle functions.
The config file is bundled with your project, so code imported in the config file is also bundled,
which can have an effect on build times and cold start duration. One important qualification is
anything defined in the
build
config is automatically stripped out of the config file, and
imports used inside build config with be tree-shaken out.Lifecycle functions
You can add lifecycle functions to get notified when any task starts, succeeds, or fails usingonStart
, onSuccess
and onFailure
:
trigger.config.ts
Instrumentations
We use OpenTelemetry (OTEL) for our run logs. This means you get a lot of information about your tasks with no effort. But you probably want to add more information to your logs. For example, here’s all the Prisma calls automatically logged:
trigger.config.ts
file.
trigger.config.ts
Package | Description |
---|---|
@opentelemetry/instrumentation-undici | Logs all fetch calls (inc. Undici fetch) |
@opentelemetry/instrumentation-http | Logs all HTTP calls |
@prisma/instrumentation | Logs all Prisma calls, you need to enable tracing |
@traceloop/instrumentation-openai | Logs all OpenAI calls |
@opentelemetry/instrumentation-fs
which logs all file system calls is currently not supported.Runtime
We currently only officially support thenode
runtime, but you can try our experimental bun
runtime by setting the runtime
option in your config file:
trigger.config.ts
Default machine
You can specify the default machine for all tasks in your project:trigger.config.ts
Log level
You can set the log level for your project:trigger.config.ts
logLevel
only determines which logs are sent to the Trigger.dev instance when using the logger
API. All console
based logs are always sent.
Max duration
You can set the defaultmaxDuration
for all tasks in your project:
trigger.config.ts
Build configuration
You can customize the build process using thebuild
option:
trigger.config.ts
The
trigger.config.ts
file is included in the bundle, but with the build
configuration
stripped out. These means any imports only used inside the build
configuration are also removed
from the final bundle.External
All code is bundled by default, but you can exclude some packages from the bundle using theexternal
option:
trigger.config.ts
node_modules
directory.
Each entry in the external should be a package name, not necessarily the import path. For example, if you want to exclude the ai
package, but you are importing ai/rsc
, you should just include ai
in the external
array:
trigger.config.ts
Any packages that install or build a native binary should be added to external, as native binaries
cannot be bundled. For example,
re2
, sharp
, and sqlite3
should be added to external.JSX
You can customize thejsx
options that are passed to esbuild
using the jsx
option:
trigger.config.ts
React
in your JSX files. You can disable this by setting automatic
to false
.
See the esbuild JSX documentation for more information.
Conditions
You can add custom import conditions to your build using theconditions
option:
trigger.config.ts
react-server
condition will resolve ai/rsc
to the server version of the ai/rsc
export.
Custom conditions will also be passed to the node
runtime when running your tasks.
Extensions
Build extension allow you to hook into the build system and customize the build process or the resulting bundle and container image (in the case of deploying). You can use pre-built extensions by installing the@trigger.dev/build
package into your devDependencies
, or you can create your own.
additionalFiles
Import theadditionalFiles
build extension and use it in your trigger.config.ts
file:
files
array to the build directory. The files
array can contain globs. The output paths will match the path of the file, relative to the root of the project.
The root of the project is the directory that contains the trigger.config.ts file
additionalPackages
Import the additionalPackages
build extension and use it in your trigger.config.ts
file:
exec
. We will try to automatically resolve the version of the package but you can specify the version by using the @
symbol:
emitDecoratorMetadata
If you need support for the emitDecoratorMetadata
typescript compiler option, import the emitDecoratorMetadata
build extension and use it in your trigger.config.ts
file:
emitDecoratorMetadata works by hooking into the esbuild bundle process and using the TypeScript
compiler API to compile files where we detect the use of decorators. This means you must have
emitDecoratorMetadata
enabled in your tsconfig.json
file, as well as typescript
installed in
your devDependencies
.Prisma
If you are using Prisma, you should use the prisma build extension.- Automatically handles copying prisma files to the build directory.
- Generates the prisma client during the deploy process
- Optionally will migrate the database during the deploy process
- Support for TypedSQL and multiple schema files.
This does not have any effect when running the
dev
command, only when running the deploy
command.migrate
option:
generator
statements defined in your schema file, you can pass in the clientGenerator
option to specify the prisma-client-js
generator, which will prevent other generators from being generated:
typedSql
option:
The
prismaExtension
will inject the DATABASE_URL
environment variable into the build process. Learn more about setting environment variables for deploying in our Environment Variables guide.These environment variables are only used during the build process and are not embedded in the final container image.syncEnvVars
ThesyncEnvVars
build extension replaces the deprecated resolveEnvVars
export. Check out our syncEnvVars documentation for more information.
audioWaveform
Previously, we installed Audio Waveform in the build image. That’s been moved to a build extension:puppeteer
WEB SCRAPING: When web scraping, you MUST use a proxy to comply with our terms of service. Direct scraping of third-party websites without the site owner’s permission using Trigger.dev Cloud is prohibited and will result in account suspension. See this example using a proxy.
trigger.config.ts
file:
trigger.config.ts
ffmpeg
You can add theffmpeg
build extension to your build process:
ffmpeg
that is available in the Debian package manager. If you need a specific version, you can pass in the version as an argument:
FFMPEG_PATH
and FFPROBE_PATH
to your environment variables, making it easy to use popular ffmpeg libraries like fluent-ffmpeg
.
Follow this example to get setup with Trigger.dev and FFmpeg in your project.
esbuild plugins
You can easily add existing or custom esbuild plugins to your build process using theesbuildPlugin
extension:
aptGet
You can install system packages into the deployed image using using theaptGet
extension:
Custom extensions
You can create your own extensions to further customize the build process. Extensions are an object with aname
and zero or more lifecycle hooks (onBuildStart
and onBuildComplete
) that allow you to modify the BuildContext
object that is passed to the build process through adding layers. For example, this is how the aptGet
extension is implemented:
trigger.config.ts
file:
trigger.config.ts
@trigger.dev/build
package for inspiration, which you can see in our repo here