Skip to content

fix: replace @bugsnag/cuid with nanoid for edge compatibility (#3147)#3175

Closed
deepshekhardas wants to merge 3 commits intotriggerdotdev:mainfrom
deepshekhardas:fix/supabase-edge-cuid
Closed

fix: replace @bugsnag/cuid with nanoid for edge compatibility (#3147)#3175
deepshekhardas wants to merge 3 commits intotriggerdotdev:mainfrom
deepshekhardas:fix/supabase-edge-cuid

Conversation

@deepshekhardas
Copy link

Summary

The @bugsnag/cuid package used in packages/core to generate internal IDs relies on Node.js-specific APIs like process.pid and os.hostname(). These APIs are not available in Edge runtimes like Supabase Edge Functions (Deno), causing the SDK to throw a TypeError: Cannot read properties of undefined (reading 'toString').

This PR replaces @bugsnag/cuid with nanoid, which is already a project dependency and is compatible with Edge/Deno runtimes.

Closes #3147

Changes

  • Replaced @bugsnag/cuid with nanoid in packages/core/src/v3/isomorphic/friendlyId.ts.
  • Removed @bugsnag/cuid from packages/core/package.json.

Testing

  • Verified that generateInternalId() still produces unique, URL-safe alphanumeric IDs using nanoid.
  • Code compiles and existing ID generation logic remains consistent.

deepshekhardas added 3 commits February 23, 2026 14:57
Corrected the order of env file loading to follow standard precedence conventions where local and environment-specific files override the base .env file.
@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: bd0414a

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

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
Contributor

github-actions bot commented Mar 5, 2026

Hi @deepshekhardas, 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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3afeaba1-e848-42c1-9c58-038be7ba4b34

📥 Commits

Reviewing files that changed from the base of the PR and between c013322 and bd0414a.

📒 Files selected for processing (4)
  • .changeset/fix-env-loading-precedence.md
  • packages/cli-v3/src/utilities/dotEnv.ts
  • packages/core/package.json
  • packages/core/src/v3/isomorphic/friendlyId.ts

Walkthrough

This pull request modifies three files to update environment variable resolution and internal ID generation. The primary change reorders and updates the list of environment variable files considered during dot-env loading in the CLI utilities. A second change replaces the internal ID generation mechanism from cuid() to idGenerator(), removing a dependency on @bugsnag/cuid. A third change is a formatting adjustment in the package.json file. No exported or public API signatures were altered.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@github-actions github-actions bot closed this Mar 5, 2026
Copy link
Contributor

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

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 Dead @bugsnag/cuid dependency left in package.json after removing its only import

The import cuid from "@bugsnag/cuid" was removed from packages/core/src/v3/isomorphic/friendlyId.ts (the only file that used it), but "@bugsnag/cuid": "^3.1.1" was not removed from packages/core/package.json:171. This means @bugsnag/cuid is a dead runtime dependency that will still be installed and bundled for all consumers of @trigger.dev/core, adding unnecessary bloat — which is ironic given the PR's stated goal of improving edge compatibility by removing cuid.

(Refers to line 171)

Open in Devin Review

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

Comment on lines 9 to 11
export function generateInternalId() {
return cuid();
return idGenerator();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🚩 nanoid character set is compatible with existing cuid-based database IDs

The switch from cuid() to idGenerator() (nanoid with alphabet 123456789abcdefghijkmnopqrstuvwxyz, length 21) changes the format of newly generated internal IDs. CUIDs are 25 chars from [a-z0-9]; nanoid IDs will be 21 chars from a 33-char subset ([a-z0-9] minus 0 and l). The database schema uses String columns with @default(cuid()) as a Prisma fallback, but IdUtil.generate() provides the ID explicitly. Since both old and new IDs are plain strings stored in unconstrained String columns, there's no schema incompatibility. However, new IDs will not sort chronologically the way CUIDs do (CUIDs embed a timestamp). If any code path depends on lexicographic ID ordering correlating with creation time, this could be a subtle behavioral change. A search of the run-engine for sorting/ordering by raw ID didn't surface any such pattern, but this is worth being aware of.

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: SDK fails in Supabase Edge (Deno) runtime when calling task.trigger()

1 participant