Skip to content

fix(sdk): resolve ReferenceError in envvars.update outside task context#4291

Closed
ANSHSINGH050404 wants to merge 1 commit into
triggerdotdev:mainfrom
ANSHSINGH050404:fix/envvars-update-out-of-task-context
Closed

fix(sdk): resolve ReferenceError in envvars.update outside task context#4291
ANSHSINGH050404 wants to merge 1 commit into
triggerdotdev:mainfrom
ANSHSINGH050404:fix/envvars-update-out-of-task-context

Conversation

@ANSHSINGH050404

Copy link
Copy Markdown

Closes #4264

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Summary

envvars.update(projectRef, slug, name, params) crashed outside a task run with:

ReferenceError: name is not defined

In the non-task branch the third parameter is named nameOrRequestOptions, but the code assigned $name = name!. That identifier is not a parameter (and is only a browser global), so Node throws.

create / del / retrieve / list were already fine on the same path.

Fix

  • Validate typeof nameOrRequestOptions === string (clear error if missing)
  • Assign $name = nameOrRequestOptions
  • Type-level overload coverage for in-task and out-of-task forms
  • Patch changeset for @trigger.dev/sdk

Testing

pnpm run build --filter @trigger.dev/sdk
pnpm --filter @trigger.dev/sdk exec vitest run src/v3/triggerClient.types.test.ts --run
  • Build succeeded
  • 11/11 type tests passed (including the new envvars.update overload cases)
  • Compiled dist/commonjs/v3/envvars.js uses nameOrRequestOptions for $name

Changelog

Fix envvars.update() throwing ReferenceError: name is not defined when called outside a task run (for example from a deploy script).

Note for maintainers

Vouch request: #4290

The non-task overload of envvars.update assigned $name from an undeclared
`name` identifier instead of `nameOrRequestOptions`, so management-API
calls threw ReferenceError in Node. Validate and use the real parameter.

Closes triggerdotdev#4264
@changeset-bot

changeset-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9a71ef6

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

This PR includes changesets to release 26 packages
Name Type
@trigger.dev/sdk Patch
@trigger.dev/python Patch
@internal/dashboard-agent Patch
@internal/sdk-compat-tests Patch
@trigger.dev/build Patch
@trigger.dev/core Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
@trigger.dev/rbac Patch
@trigger.dev/sso Patch
trigger.dev Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/run-store Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/tsql 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

@github-actions

Copy link
Copy Markdown
Contributor

Hi @ANSHSINGH050404, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e025c1b6-6373-4a7d-bc1f-7778c6f795b4

📥 Commits

Reviewing files that changed from the base of the PR and between a7c734c and 9a71ef6.

📒 Files selected for processing (3)
  • .changeset/envvars-update-name-scope.md
  • packages/trigger-sdk/src/v3/envvars.ts
  • packages/trigger-sdk/src/v3/triggerClient.types.test.ts

Walkthrough

Updated envvars.update() to require a string environment variable name in the out-of-task path and use it directly in the update payload. Added type-level coverage for both project-context and in-task overloads. Added a Changesets patch entry for @trigger.dev/sdk.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 In-task 4-arg update form sends slug as projectRef

The PR fixes the out-of-task branch (envvars.ts:335-346), which is now correct. However the in-task branch of the same update function has a related pre-existing bug that this PR does not address. When update(projectRef, slug, name, params) (the 4-arg overload) is called from inside a task, taskContext.ctx is truthy and slugOrParams is a string, so execution enters envvars.ts:307-319. There $projectRef = slugOrParams assigns the slug argument to the project ref (envvars.ts:308), and $slug = slugOrParams ?? taskContext.ctx.environment.slug also resolves to the slug — so the real projectRefOrName (the actual project ref) is dropped entirely and the wrong value is sent to updateEnvVar. Compare with create/upload (envvars.ts:147-152) which correctly use $projectRef = projectRefOrParams and derive $slug from slugOrRequestOptions. Additionally the $name fallback at envvars.ts:310-313 falls back to environment.slug rather than throwing/using the name, which is also incorrect. This branch is reachable because the type overloads permit the 4-arg form regardless of task context. It is outside the changed diff hunk so it could not be reported as a bug, but a reviewer should decide whether to fix it in the same PR since it is in the exact function being patched.

(Refers to lines 307-324)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

bug: envvars.update() throws "ReferenceError: name is not defined" outside a task context

1 participant