fix(next): silence OpenTelemetry "Critical dependency" warnings in build#555
Open
Vadman97 wants to merge 1 commit into
Open
fix(next): silence OpenTelemetry "Critical dependency" warnings in build#555Vadman97 wants to merge 1 commit into
Vadman97 wants to merge 1 commit into
Conversation
`@highlight-run/node` pulls `@opentelemetry/instrumentation` and uses `require-in-the-middle`, which webpack cannot statically analyze. Next.js emits a wall of "Critical dependency: the request of a dependency is an expression" warnings during `next build` in every customer app that uses `registerHighlight` from `instrumentation.ts`. `withHighlightConfig` now (1) adds the OpenTelemetry / RITM / ITM packages to `serverExternalPackages` so Next defers to Node's runtime require, and (2) registers `ignoreWarnings` on the server webpack config as defense-in-depth for workspace and hoisted setups. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
abelonogov-ld
approved these changes
May 13, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Backend Next.js apps using
@highlight-run/next/server(typically viainstrumentation.ts) currently emit a wall ofCritical dependency: the request of a dependency is an expressionwarnings duringnext build. The root cause is that@highlight-run/nodepulls@opentelemetry/instrumentation(via@prisma/instrumentation) and usesrequire-in-the-middle/import-in-the-middle, which webpack cannot statically analyze.This PR teaches
withHighlightConfigto suppress these warnings out of the box so customers don't need to know about the underlying webpack quirk:serverExternalPackages, so Next defers to Node's runtimerequireinstead of bundling them. Preserves any existing user-provided entries and deduplicates.ignoreWarningsfilters to the server webpack config covering bothnode_modules/...(typical install) andhighlight-node/dist/...(workspace / hoisted) paths, scoped to the exact warning message.Verified against the
e2e/nextjsexample: theCritical dependencywarnings that were present before this change are gone after it. Existingwith-highlight-configunit tests still pass; added four new tests coveringserverExternalPackagesmerge/dedup and the server-onlyignoreWarningsbehavior.Test plan
yarn workspace @highlight-run/next test— 15/15 passyarn turbo run lint --filter=@highlight-run/next— cleanyarn format-check— cleane2e/nextjsnext buildno longer emitsCritical dependencywarnings (pre-existing unrelated type error in the example is untouched)🤖 Generated with Claude Code
Note
Medium Risk
Changes Next.js server build configuration by externalizing OpenTelemetry-related packages and suppressing specific webpack warnings, which could affect server bundling behavior in some deployments.
Overview
Reduces noisy
next buildoutput for apps using Highlight + OpenTelemetry by automatically treating several OTel/Prisma and*-in-the-middlemodules as server externals viaserverExternalPackages, while preserving user entries and deduplicating.Adds a server-only webpack
ignoreWarningsfilter for the known OpenTelemetry “Critical dependency” warning (including hoisted/workspace layouts), and extends unit tests to cover the externals merge/dedup behavior and the server-vs-client warning suppression.Reviewed by Cursor Bugbot for commit 617f721. Bugbot is set up for automated code reviews on this repo. Configure here.