Skip to content

fix(cli): set NODE_ENV for Bun worker compilation - #5164

Draft
ethandaniel wants to merge 2 commits into
triggerdotdev:mainfrom
ethandaniel:bun-worker-production
Draft

ethandaniel wants to merge 2 commits into
triggerdotdev:mainfrom
ethandaniel:bun-worker-production

Conversation

@ethandaniel

Copy link
Copy Markdown

Summary

Bun inlines process.env.NODE_ENV when it compiles a worker. If NODE_ENV is unset during compilation, the task sees development even when the runtime container supplies NODE_ENV=production. This can send deployed tasks down development-only code paths. Bun compiler docs

Set NODE_ENV=production for the bun build command only. This gives Bun the correct value at compile time and preserves the existing minification behavior.

Testing

  • Reproduced the issue on Trigger.dev’s Bun 1.4.4 build image.
  • Passed 65 targeted CLI tests before syncing the branch with upstream main, including the Docker regression test. The test starts with NODE_ENV unset, builds the worker, and verifies that the compiled task sees production.

Changelog

Deployed Bun 1.4 tasks now see NODE_ENV=production when bytecode compilation is enabled.

@changeset-bot

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a8bb5aa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
trigger.dev Patch
@trigger.dev/build Patch
@trigger.dev/convex Patch
@trigger.dev/core Patch
@trigger.dev/linear Patch
@trigger.dev/python Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/slack Patch
@trigger.dev/sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Bun compile command now runs with NODE_ENV=production. The compiled-worker test checks that the worker reports NODE_ENV=production when launched. A changeset records the patch release.

Merge Risk: Minimal · up to a8bb5

Deployed Bun workers are now compiled with NODE_ENV=production, so compiled tasks should no longer take development-only paths. No concrete merge-blocking risk was found, and the change is easy to revert.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(cli): set NODE_ENV for Bun worker compilation" matches the main change. The changeset sets NODE_ENV=production for the bun build command in packages/cli-v3/src/deploy/buildImage.ts, and…
Description check Passed The description follows the repository template. It explains the problem, which is Bun inlining process.env.NODE_ENV at compile time, and it gives the fix, which sets NODE_ENV=production for the bun b…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(cli): set NODE_ENV for Bun worker compilation" matches the main change. The changeset sets NODE_ENV=production for the bun build command in packages/cli-v3/src/deploy/buildImage.ts, and the test verifies the compiled worker sees production. It uses a conventional commit prefix and names the affected component. It is specific and concise, and it fits the title convention.

Full details: Description check

Explanation

The description follows the repository template. It explains the problem, which is Bun inlining process.env.NODE_ENV at compile time, and it gives the fix, which sets NODE_ENV=production for the bun build command only. It includes a Testing section with concrete steps and a Changelog entry. The template checklist, the Closes #<issue> line, and the Screenshots section are missing. The Closes line is needed to link the issue, but the PR objectives reference PR #5164 and no linked issue is given. The checklist items are not ticked.

Resolution

Optionally add a "Closes #<issue>" line if a related issue exists, tick the checklist items that apply, and add a Screenshots entry or mark it not applicable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0e7a8baf-28aa-4e4c-9152-ffeeb73a32a7
Commits

Reviewing files that changed from the base of the PR and between 38aeef8 and a8bb5aa.

Files selected for processing: 3

  • .changeset/fix-bun-worker-node-env.md
  • packages/cli-v3/src/build/bundle.test.ts
  • packages/cli-v3/src/deploy/buildImage.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Recent review details

Additional context used

Code guidelines: 4

.claude/rules/sdk-packages.md — auto-discovered
.cursor/rules/writing-tasks.mdc — auto-discovered
packages/cli-v3/AGENTS.md — auto-discovered
.github/copilot-instructions.md — auto-discovered
Path-based instructions: 4

Source excerpt: Changes to `packages/` are **customer-facing**.

CodeRabbit inference engine (.claude/rules/sdk-packages.md)

Files:

  • packages/cli-v3/src/build/bundle.test.ts
  • packages/cli-v3/src/deploy/buildImage.ts
Source excerpt: You MUST import from `@trigger.dev/sdk` (NEVER `@trigger.dev/sdk/v3`) Source excerpt: You MUST NEVER use `client.defineJob` Source excerpt: YOU MUST `export` every task, including subtasks Source excerpt: Key points: Each ta...

CodeRabbit inference engine (.cursor/rules/writing-tasks.mdc)

Files:

  • .changeset/fix-bun-worker-node-env.md
  • packages/cli-v3/src/build/bundle.test.ts
  • packages/cli-v3/src/deploy/buildImage.ts
Source excerpt: The `rules/` directory at the repo root contains versioned SDK documentation that gets installed alongside customer projects.

CodeRabbit inference engine (packages/cli-v3/AGENTS.md)

Files:

  • packages/cli-v3/src/build/bundle.test.ts
  • packages/cli-v3/src/deploy/buildImage.ts
Source excerpt: This is the repo for Trigger.dev, a background jobs platform written in TypeScript.

CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • packages/cli-v3/src/build/bundle.test.ts
  • packages/cli-v3/src/deploy/buildImage.ts
Additional comments: 2

packages/cli-v3/src/deploy/buildImage.ts: 2

1045-1045: Functional Correctness

The comment asks whether an earlier bundling step can fix process.env.NODE_ENV to "development" before this compile step. The inspected build options do not define that replacement. The regression fixture follows the same bundling path and checks that the compiled task sees production, so the reported failure path is not supported by the code in this PR.

1043-1043: Stability & Availability

This concern is not supported. The change runs env NODE_ENV=production bun build ... in exec form, which requires env on the image PATH. The inspected self-hosting contract for custom build images lists the required contents (the base image's contents plus python3, make, and g++), does not require or exclude env, and expects a Debian-based image on the apt path. No inspected source or documentation establishes a supported custom buildBase that omits env, so the claimed deployment failure has no supported trigger.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant