You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes several issues that arise when using the SDK inside monorepo setups (e.g. Turborepo, Nx) and with certain ORM driver adapters. The Next.js version detection now falls back to Node's module resolution for hoisted packages, a turbopack config key is preserved to avoid errors in Next.js 16+, and the pg instrumentation is hardened against non-thenable return values from query().
Changes
src/nextjs/utils.ts — getNextjsVersion() now falls back to require.resolve("next/package.json") when the cwd-based node_modules lookup fails, supporting monorepos where next is hoisted to a root node_modules.
src/nextjs/withTuskDrift.ts — Preserves the user's turbopack config (or sets an empty object) so Next.js 16+ doesn't error when it detects a webpack config without a turbopack counterpart.
src/instrumentation/libraries/pg/Instrumentation.ts — Adds a guard for when originalQuery returns a non-thenable value (e.g. Prisma's driver adapter), preventing a Cannot read properties of undefined (reading 'then') crash
Tusk's tests are all passing and cover the three critical fixes in this PR. The pg instrumentation tests validate that the guard against non-thenable return values works across multiple edge cases—undefined, null, plain objects, and malformed then properties—ensuring compatibility with ORM adapters like Prisma without breaking standard Promise-based queries. The Next.js version detection tests confirm the fallback to require.resolve handles monorepo setups where next is hoisted, while also covering graceful degradation for missing files, invalid JSON, permission errors, and incomplete package.json files. Together, these tests protect against runtime crashes in real-world monorepo and adapter scenarios.
Key Points:
pg instrumentation — Five high-value tests ensure the _wrapQueryWithInstrumentation guard prevents crashes from non-thenable query returns while maintaining normal Promise flow
Next.js version detection — Eight tests validate monorepo compatibility via require.resolve fallback and robust error handling across file system edge cases
Hot paths covered — ORM adapter compatibility (Prisma) and monorepo dependency resolution, both critical for production stability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes several issues that arise when using the SDK inside monorepo setups (e.g. Turborepo, Nx) and with certain ORM driver adapters. The Next.js version detection now falls back to Node's module resolution for hoisted packages, a
turbopackconfig key is preserved to avoid errors in Next.js 16+, and the pg instrumentation is hardened against non-thenable return values fromquery().Changes
src/nextjs/utils.ts—getNextjsVersion()now falls back torequire.resolve("next/package.json")when thecwd-basednode_moduleslookup fails, supporting monorepos wherenextis hoisted to a rootnode_modules.src/nextjs/withTuskDrift.ts— Preserves the user'sturbopackconfig (or sets an empty object) so Next.js 16+ doesn't error when it detects awebpackconfig without aturbopackcounterpart.src/instrumentation/libraries/pg/Instrumentation.ts— Adds a guard for whenoriginalQueryreturns a non-thenable value (e.g. Prisma's driver adapter), preventing aCannot read properties of undefined (reading 'then')crash