nextjs - 💡(How to fix) Fix Cannot access 'BaseSender' before initialization when using Azure Monitor and Turpopack [7 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85170Fetched 2026-04-08 02:17:13
View on GitHub
Comments
7
Participants
4
Timeline
15
Reactions
3
Author
Timeline (top)
commented ×7subscribed ×3labeled ×2cross-referenced ×1

Error Message

ReferenceError: An error occurred while loading instrumentation hook: Cannot access 'BaseSender' before initialization

Code Example

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025
  Available memory (MB): 31932
  Available CPU cores: 28
Binaries:
  Node: 22.20.0
  npm: 10.9.3
  Yarn: 1.22.22
  pnpm: 10.18.3
Relevant Packages:
  next: 15.5.6 // Latest available version is detected (15.5.6).
  eslint-config-next: 15.5.5
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: standalone

Also tried 16.0.0-canary.15, 15.6.0-canary.37 & 15.6.0-canary.36
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/ksstott/nextjs-azure-monitor

To Reproduce

  1. Create a next js app with '@azure/monitor-opentelemetry'
  2. Create an instrumentation.ts file importing and calling the useAzureMonitor method
  3. Try to run the server using npm run dev (Also happens when running output of npm run build using standalone output)

Current vs. Expected behavior

Current behaviour ReferenceError: An error occurred while loading instrumentation hook: Cannot access 'BaseSender' before initialization

Expected: The code imports and runs successfully

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025
  Available memory (MB): 31932
  Available CPU cores: 28
Binaries:
  Node: 22.20.0
  npm: 10.9.3
  Yarn: 1.22.22
  pnpm: 10.18.3
Relevant Packages:
  next: 15.5.6 // Latest available version is detected (15.5.6).
  eslint-config-next: 15.5.5
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: standalone

Also tried 16.0.0-canary.15, 15.6.0-canary.37 & 15.6.0-canary.36

Which area(s) are affected? (Select all that apply)

Instrumentation

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

Already discussed here prior to raising issue https://github.com/vercel/next.js/discussions/85096

extent analysis

TL;DR

The issue is likely due to a circular dependency in the @azure/monitor-opentelemetry package, and a potential workaround is to reorganize the imports or update the package version.

Guidance

  • Verify the import order in the instrumentation.ts file to ensure that useAzureMonitor is not being called before its dependencies are initialized.
  • Check the @azure/monitor-opentelemetry package documentation for any known issues or circular dependency problems.
  • Consider updating the @azure/monitor-opentelemetry package to the latest version, if available, to see if the issue is resolved.
  • Review the discussion on https://github.com/vercel/next.js/discussions/85096 for any additional insights or potential workarounds.

Example

No specific code example is provided due to the lack of detailed code information in the issue.

Notes

The issue may be specific to the @azure/monitor-opentelemetry package and its interaction with Next.js, and further investigation is needed to determine the root cause.

Recommendation

Apply workaround: Reorganize the imports in the instrumentation.ts file to avoid circular dependencies, and consider updating the @azure/monitor-opentelemetry package to the latest version if available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Cannot access 'BaseSender' before initialization when using Azure Monitor and Turpopack [7 comments, 4 participants]