fix(nextjs): Use env variable for build detection #4608
Merged
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.
In non-Vercel-deployed nextjs apps using our SDK, we instrument the server in order to be able to capture transactions for a wider variety of incoming requests than is possible using our
withSentry
API route handler wrapper. We don't do this during build, however, because there's no server to wrap.Until now, we've been relying on the fact that child processes of the main build process were invoked by
node <path>/node_modules/jest-worker/build/workers/processChild.js
in order to recognize them as such. Recently, however, next started vendoring pre-compiled versions of more of its dependencies, includingjest-worker
, such that now those child process are invoked bynode <path>/node_modules/next/dist/compiled/jest-worker/processChild.js
. This broke our build detection.Rather than just switch to using the new path, this PR refactors the check to use an env variable set by the main build process, in order that the check not get fooled by any child processes spawned at runtime. (I don't actually know if that ever happens, but there's no reason it couldn't, so better to have a foolproof indicator.)