trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

[TRI-2795] Add bun support

Open matt-aitken opened this issue 1 year ago • 4 comments

Currently if you use bun it actually just uses npm (we detect a bun lock file and fallback to using npm).

Adding official bun support would mean you could call postinstall scripts using bun and do other bun specific things. As bun is a package manager and a runtime there are various levels of support we could go to.

TRI-2795

matt-aitken avatar Jun 28 '24 18:06 matt-aitken

Just in case anybody else needs this, I was hitting version mismatch errors after updating the sdk package (with bun update). What I had to do was to delete the bun cache (on MacOS is at /private/tmp/bunx-501-trigger.dev@beta) and everything started working again.

Otherwise with bun everything works pretty seamlessly, here's what I did:

  1. Install trigger.dev with bun add @trigger.dev/[email protected]
  2. Create a project manually on https://cloud.trigger.dev
  3. Create manually the trigger.config.ts on the project root folder:
import type { TriggerConfig } from '@trigger.dev/sdk/v3';
 
export const config: TriggerConfig = {
 project: 'project id as found under project settings on https://cloud.trigger.dev',
 logLevel: 'log',
 retries: {
  enabledInDev: true,
  default: {
   maxAttempts: 3,
   minTimeoutInMs: 1000,
   maxTimeoutInMs: 10000,
   factor: 2,
   randomize: true
  }
 },
 triggerDirectories: ['./trigger'],
};
  1. And obviously tasks e.g. /trigger/example.ts:
import { logger, task, wait } from '@trigger.dev/sdk/v3';

export const helloWorldTask = task({
	id: 'hello-world',
	run: async (payload: any, { ctx }) => {
		logger.log('Hello, world!', { payload, ctx });

		await wait.for({ seconds: 5 });

		return {
			message: 'Hello, world!'
		};
	}
});

You can now run it with bunx trigger.dev@beta dev.

cellulosa avatar Aug 05 '24 13:08 cellulosa

@cellulosa What framework are you using here?

bunx trigger.dev@beta dev seems to have problems picking up the default nextjs install which creates a src/jobs folder, despite correctly changing the trigger directory in the config.

It seems the default nextjs install doesn't even make a trigger.config.ts file but when you bunx it looks for it. Maybe I'm missing something here?

jjsessa avatar Aug 11 '24 08:08 jjsessa

You' re right I should have said... I'm working with sveltekit

cellulosa avatar Aug 11 '24 13:08 cellulosa

This does not work for me either Now I'm getting "cannot resolve bun"

Nnadivictory25 avatar Oct 11 '24 04:10 Nnadivictory25