Development

EACCES: permission denied

If you see this error:

6090 verbose stack Error: EACCES: permission denied, rename '/Users/user/.npm/_cacache/tmp/f1bfea11' -> '/Users/user/.npm/_cacache/content-v2/sha512/31/d8/e094a47a0105d06fd246892ed1736c02eae323726ec6a3f34734eeb71308895dfba4f4f82a88ffe7e480c90b388c91fc3d9f851ba7b96db4dc33fbc65528'

First, clear the npm cache:

npm cache clean --force

Then change the permissions of the npm folder (if 1 doesn’t work):

sudo chown -R $(whoami) ~/.npm

Deployment

Running the [trigger.dev deploy] command builds and deploys your code. Sometimes there can be issues building your code.

You can run the deploy command with --log-level debug at the end. This will spit out a lot of information about the deploy. If you can’t figure out the problem from the information below please join our Discord and create a help forum post. Do NOT share the extended debug logs publicly as they might reveal private information about your project.

Here are some common problems and their solutions:

Typecheck failed, aborting deployment

We typecheck your code before deploying. If the typecheck fails, the deployment is aborted. You should see logs with details about the typecheck failure.

You can skip typechecking, by adding the --skip-typecheck flag when calling deploy.

Error: Cannot find module 'X'

This errors occurs if we can’t figure out how to automatically import some code. You can fix this by adding it to the dependenciesToBundle array in the trigger.config file.

Failed to build project image: Error building image

There should be a link below the error message to the full build logs on your machine. Take a look at these to see what went wrong. Join our Discord and you share it privately with us if you can’t figure out what’s going wrong. Do NOT share these publicly as the verbose logs might reveal private information about your project.

Deployment timed out

The last stage of deployment is to run it on our servers – we register the new versions of your tasks with the dashboard during this step. We allow 3 mins for this to succeed or fail. If it fails then you’ll see this error.

The first thing to do is to try again. If that fails then join our Discord and create a Help forum post with a link to your deployment.

Deployment encountered an error

Usually there will be some useful guidance below this message. If you can’t figure out what’s going wrong then join our Discord and create a Help forum post with a link to your deployment.

Project setup issues

The requested module 'node:events' does not provide an export named 'addAbortListener'

If you see this error it means you’re not a supported version of Node:

SyntaxError: The requested module 'node:events' does not provide an export named 'addAbortListener'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)

Node.js v19.9.0

You need to be on at least these minor versions:

VersionMinimum
1818.16+
2020.11+
2121.0+

Runtime issues

Environment variable not found:

Your code is deployed separately from the rest of your app(s) so you need to make sure that you set any environment variables you use in your tasks in the Trigger.dev dashboard. Read the guide.

Error: @prisma/client did not initialize yet.

Prisma uses code generation to create the client from your schema file. This means you need to add a bit of config so we can generate this file before your tasks run: read the guide.

When triggering subtasks the parent task finishes too soon

Make sure that you always use await when you call trigger, triggerAndWait, batchTrigger, and batchTriggerAndWait. If you don’t then it’s likely the task(s) won’t be triggered because the calling function process can be terminated before the networks calls are sent.

Rate limit exceeded

The most common cause of hitting the API rate limit is if you’re calling trigger() on a task in a loop, instead of doing this use batchTrigger() which will trigger multiple tasks in a single API call. You can have up to 100 tasks in a single batch trigger call.

View the rate limits page for more information.

Framework specific issues

NestJS swallows all errors/exceptions

If you’re using NestJS and you add code like this into your tasks you will prevent any errors from being surfaced:

export const simplestTask = task({
  id: "nestjs-example",
  run: async (payload) => {
    //by doing this you're swallowing any errors
    const app = await NestFactory.createApplicationContext(AppModule);
    await app.init();

    //etc...
  },
});

NestJS has a global exception filter that catches all errors and swallows them, so we can’t receive them. Our current recommendation is to not use NestJS inside your tasks. If you’re a NestJS user you can still use Trigger.dev but just don’t use NestJS inside your tasks like this.

React is not defined

If you see this error:

Worker failed to start ReferenceError: React is not defined

Either add this to your file:

import React from "react";

Or change the tsconfig jsx setting:

{
  "compilerOptions": {
    //...
    "jsx": "react-jsx" 
  },
}

Next.js build failing due to missing API key in GitHub CI

This issue occurs during the Next.js app build process on GitHub CI where the Trigger.dev SDK is expecting the TRIGGER_SECRET_KEY environment variable to be set at build time. Next.js attempts to compile routes and creates static pages, which can cause issues with SDKs that require runtime environment variables. The solution is to mark the relevant pages as dynamic to prevent Next.js from trying to make them static. You can do this by adding the following line to the route file:

export const dynamic = "force-dynamic";

Correctly passing event handlers to React components

An issue can sometimes arise when you try to pass a function directly to the onClick prop. This is because the function may require specific arguments or context that are not available when the event occurs. By wrapping the function call in an arrow function, you ensure that the handler is called with the correct context and any necessary arguments. For example:

This works:

<Button onClick={() => myTask()}>Trigger my task</Button>

Whereas this does not work:

<Button onClick={myTask}>Trigger my task</Button>

Worker failed to start when running Dev command

An issue may occur when trying to run the development command for Trigger.dev when using certain packages like @t3-oss/env-nextjs or ORMs like Drizzle ORM. The error message typically indicates that there’s a problem with importing ES modules in a CommonJS context.

Error message
X Error: Worker failed to start Error [ERR_REQUIRE_ESM]: require() of ES Module [...] not supported.
Instead change the require of index.js in [...] to a dynamic import() which is available in all CommonJS modules.

This issue is related to how Trigger.dev bundles code and interacts with certain ES module dependencies.

To resolve this issue, follow these steps:

  1. In your trigger.config.ts file, add the problematic dependencies to the dependenciesToBundle array:
trigger.config.ts
export const config: TriggerConfig = {
  // ... other config options
  dependenciesToBundle: [
    /@t3-oss/,
    "drizzle-orm",
    /@neondatabase/,
    // Add other problematic dependencies here
  ],
};
  1. If you’re using environment variables with @t3-oss/env-nextjs, implement a resolveEnvVars function in your config file:
trigger.config.ts
import { env } from "@/env";
import type { ResolveEnvironmentVariablesFunction } from "@trigger.dev/sdk/v3";

export const resolveEnvVars: ResolveEnvironmentVariablesFunction = () => {
  return {
    variables: Object.keys(env).map((key) => ({
      name: key,
      value: env[key as keyof typeof env]?.toString(),
    })),
  };
};
  1. For users of packages that require WebSocket (like @neondatabase/serverless), you may need to set up a WebSocket polyfill if you’re using Node.js versions earlier than 22. Add this to your code:
import { neonConfig, Pool } from '@neondatabase/serverless';
import ws from 'ws';

neonConfig.webSocketConstructor = ws;