Skip to content

fix(core): Declare optional peer dependencies to resolve phantom imports under strict package managers - #6729

Open
antonis wants to merge 5 commits into
mainfrom
fix/declare-optional-peer-deps
Open

antonis wants to merge 5 commits into
mainfrom
fix/declare-optional-peer-deps

Conversation

@antonis

@antonis antonis commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

The published @sentry/react-native package imports several modules it never declares in package.json, relying on flat node_modules hoisting to resolve them. Under isolated/strict stores — pnpm's default isolated linker, Yarn PnP, and Bun — these imports can fail to resolve (MODULE_NOT_FOUND / unresolved type declarations) because a package may only reach dependencies it explicitly declares.

This declares each of them as an optional peer dependency, so they resolve when present without forcing installation on apps that don't use the related integration or build tooling (peerDependenciesMeta.optional also prevents auto-install by npm 7+/pnpm and suppresses missing-peer warnings).

Two categories, all verified against real import/require sites:

Kind Packages Example site
Runtime guarded require() @expo/config, @expo/env, dotenv, expo-router, expo-updates, open, promise, @react-navigation/native src/js/tools/utils.ts (require('@expo/config')), integrations/expoupdateslistener.ts (require('expo-updates'))
Type-only import leaking into shipped .d.ts metro, metro-resolver, @babel/core, @expo/config-types dist/js/tools/*.d.ts (import type … from 'metro')

Ranges are * for the optional integration packages (matching the sibling @sentry/expo-upload-sourcemaps, which already declares @expo/env/dotenv this way, and the SDK's own supported react-native floor which ships older Metro); @babel/core uses >=7.0.0.

No runtime behavior change: every affected require is already wrapped in try/catch or gated behind an integration the user opted into, and the type-only imports are erased at build time.

💡 Motivation and Context

https://nubjs.com/blog/phantom-dependencies-package-extensions

💚 How did you test it?

  • CI
  • Manual local builds

📝 Checklist

  • I added tests to verify changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.
  • No breaking changes.

🔮 Next steps

🤖 Generated with Claude Code

…rts under strict package managers

The published package imports several modules it never declares, relying
on flat node_modules hoisting to resolve them. Under isolated/strict
stores (pnpm's default isolated linker, Yarn PnP, Bun) these fail to
resolve. Declare them as optional peer dependencies so they resolve when
present, without forcing installation on apps that don't use the related
integration or build tooling.

- Runtime guarded requires: @expo/config, @expo/env, dotenv, expo-router,
  expo-updates, open, promise, @react-navigation/native
- Type-only .d.ts references: metro, metro-resolver, @babel/core,
  @expo/config-types

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@antonis
antonis force-pushed the fix/declare-optional-peer-deps branch from a4524ad to 42b5de1 Compare September 16, 2026 12:16
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • fix(core): Declare optional peer dependencies to resolve phantom imports under strict package managers by antonis in #6729
  • fix(ios): Honor shutdownTimeout on iOS by antonis in #6749

🤖 This preview updates automatically when you update the PR.

@antonis antonis added the ready-to-merge Triggers the full CI test suite label Sep 16, 2026
Comment thread packages/core/package.json
Declaring the optional peers moved several packages out of the workspace's
own node_modules (a peer is expected to be provided by the consumer), which
broke the SDK's own build, type-aware lint, and tests:

- Type-only imports lost their types: metro-resolver (metroconfig.ts),
  @expo/config-types (plugin/withSentry.ts) -> oxlint type-aware errors.
- jest.mock('@expo/config') could no longer resolve -> tools test suites
  failed to load.
- promise/setimmediate stopped resolving -> setImmediate-based transport
  flush broke, so tracing/profiling suites captured no transaction.

Add these back as devDependencies (matching the existing metro/@babel/core
pattern) so the workspace builds and tests itself, while keeping them as
optional peers for consumers. Also declare metro-config as an optional peer
(metroMiddleware.ts imports its types, re-exported via metro.d.ts).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 435.90 ms 461.47 ms 25.57 ms
Size 50.56 MiB 56.49 MiB 5.93 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
a2585ce+dirty 426.36 ms 483.26 ms 56.90 ms
882f8ae+dirty 399.98 ms 427.06 ms 27.08 ms
af33f3b+dirty 434.90 ms 506.14 ms 71.24 ms
ecf47a2+dirty 420.40 ms 458.02 ms 37.62 ms
acd838e+dirty 422.63 ms 462.39 ms 39.76 ms
7fd0012+dirty 444.73 ms 470.08 ms 25.35 ms
580fb5c+dirty 436.34 ms 471.63 ms 35.28 ms
5ca03f9+dirty 423.30 ms 467.00 ms 43.70 ms
5c1e987+dirty 423.52 ms 471.64 ms 48.12 ms
822d35b+dirty 429.31 ms 498.04 ms 68.73 ms

App size

Revision Plain With Sentry Diff
a2585ce+dirty 49.74 MiB 55.36 MiB 5.61 MiB
882f8ae+dirty 48.30 MiB 53.60 MiB 5.29 MiB
af33f3b+dirty 49.74 MiB 55.09 MiB 5.35 MiB
ecf47a2+dirty 49.74 MiB 54.82 MiB 5.07 MiB
acd838e+dirty 48.30 MiB 53.60 MiB 5.30 MiB
7fd0012+dirty 50.56 MiB 56.46 MiB 5.90 MiB
580fb5c+dirty 49.74 MiB 54.79 MiB 5.05 MiB
5ca03f9+dirty 49.74 MiB 55.26 MiB 5.52 MiB
5c1e987+dirty 43.75 MiB 48.08 MiB 4.33 MiB
822d35b+dirty 49.74 MiB 54.84 MiB 5.10 MiB

Previous results on branch: fix/declare-optional-peer-deps

Startup times

Revision Plain With Sentry Diff
ebf349c+dirty 522.00 ms 553.60 ms 31.60 ms

App size

Revision Plain With Sentry Diff
ebf349c+dirty 50.56 MiB 56.51 MiB 5.95 MiB

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 3849.85 ms 1224.46 ms -2625.40 ms
Size 5.15 MiB 6.90 MiB 1.75 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
0a9e622+dirty 3835.87 ms 1221.07 ms -2614.80 ms
7d6fd3a+dirty 1223.29 ms 1229.57 ms 6.28 ms
5ca03f9+dirty 3844.55 ms 1218.36 ms -2626.19 ms
774257e+dirty 3846.90 ms 1215.02 ms -2631.88 ms
40c9884+dirty 3837.72 ms 1226.61 ms -2611.11 ms
4e0b819+dirty 3839.05 ms 1210.75 ms -2628.30 ms
d038a14+dirty 3845.71 ms 1228.11 ms -2617.59 ms
57e0069+dirty 3842.29 ms 1212.12 ms -2630.17 ms
882f8ae+dirty 3840.30 ms 1224.41 ms -2615.88 ms
5125c43+dirty 3846.45 ms 1221.12 ms -2625.32 ms

App size

Revision Plain With Sentry Diff
0a9e622+dirty 4.98 MiB 6.51 MiB 1.53 MiB
7d6fd3a+dirty 3.38 MiB 4.77 MiB 1.39 MiB
5ca03f9+dirty 4.98 MiB 6.53 MiB 1.55 MiB
774257e+dirty 5.15 MiB 6.70 MiB 1.54 MiB
40c9884+dirty 4.98 MiB 6.51 MiB 1.53 MiB
4e0b819+dirty 4.98 MiB 6.46 MiB 1.49 MiB
d038a14+dirty 5.15 MiB 6.67 MiB 1.51 MiB
57e0069+dirty 4.98 MiB 6.50 MiB 1.52 MiB
882f8ae+dirty 5.15 MiB 6.70 MiB 1.54 MiB
5125c43+dirty 5.15 MiB 6.68 MiB 1.53 MiB

Previous results on branch: fix/declare-optional-peer-deps

Startup times

Revision Plain With Sentry Diff
ebf349c+dirty 3851.93 ms 1231.44 ms -2620.49 ms

App size

Revision Plain With Sentry Diff
ebf349c+dirty 5.15 MiB 6.90 MiB 1.75 MiB

@sentry

sentry Bot commented Sep 16, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Sentry RN io.sentry.reactnative.sample 8.27.0 (107) Release

⚙️ sentry-react-native Build Distribution Settings

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 8abd69b. Configure here.

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 3870.04 ms 1238.97 ms -2631.07 ms
Size 5.15 MiB 6.90 MiB 1.75 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
68ae91b+dirty 3836.36 ms 1222.04 ms -2614.32 ms
0b5a379+dirty 3857.69 ms 1230.34 ms -2627.35 ms
bf168a4+dirty 3846.83 ms 1221.33 ms -2625.49 ms
f170ec3+dirty 3844.74 ms 1222.67 ms -2622.07 ms
68672fc+dirty 3832.22 ms 1228.29 ms -2603.93 ms
84cba31+dirty 3830.40 ms 1204.44 ms -2625.96 ms
2c735cc+dirty 1223.33 ms 1224.38 ms 1.04 ms
b9bebee+dirty 3858.02 ms 1231.92 ms -2626.11 ms
a50b33d+dirty 1207.11 ms 1212.10 ms 5.00 ms
5569641+dirty 3824.35 ms 1210.78 ms -2613.57 ms

App size

Revision Plain With Sentry Diff
68ae91b+dirty 4.98 MiB 6.46 MiB 1.48 MiB
0b5a379+dirty 5.15 MiB 6.70 MiB 1.54 MiB
bf168a4+dirty 4.98 MiB 6.47 MiB 1.49 MiB
f170ec3+dirty 5.15 MiB 6.69 MiB 1.53 MiB
68672fc+dirty 5.15 MiB 6.71 MiB 1.55 MiB
84cba31+dirty 4.98 MiB 6.55 MiB 1.57 MiB
2c735cc+dirty 3.38 MiB 4.74 MiB 1.35 MiB
b9bebee+dirty 5.15 MiB 6.68 MiB 1.53 MiB
a50b33d+dirty 3.38 MiB 4.73 MiB 1.35 MiB
5569641+dirty 5.15 MiB 6.67 MiB 1.51 MiB

Previous results on branch: fix/declare-optional-peer-deps

Startup times

Revision Plain With Sentry Diff
ebf349c+dirty 3870.69 ms 1230.15 ms -2640.54 ms

App size

Revision Plain With Sentry Diff
ebf349c+dirty 5.15 MiB 6.90 MiB 1.75 MiB

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 649.43 ms 693.02 ms 43.59 ms
Size 50.56 MiB 56.49 MiB 5.93 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
f3215d3+dirty 396.53 ms 436.66 ms 40.13 ms
d0e3b3e+dirty 443.19 ms 480.00 ms 36.81 ms
a5d243c+dirty 499.20 ms 525.62 ms 26.42 ms
7fd0012+dirty 422.41 ms 445.57 ms 23.17 ms
0a147b2+dirty 442.80 ms 522.24 ms 79.44 ms
d7d54c6+dirty 423.54 ms 498.56 ms 75.02 ms
c823bb5+dirty 468.26 ms 516.16 ms 47.90 ms
5789645+dirty 502.66 ms 594.19 ms 91.53 ms
40c9884+dirty 453.76 ms 478.98 ms 25.22 ms
d771cd5+dirty 432.29 ms 464.38 ms 32.09 ms

App size

Revision Plain With Sentry Diff
f3215d3+dirty 48.30 MiB 53.49 MiB 5.19 MiB
d0e3b3e+dirty 49.74 MiB 55.09 MiB 5.34 MiB
a5d243c+dirty 48.30 MiB 53.54 MiB 5.23 MiB
7fd0012+dirty 50.56 MiB 56.46 MiB 5.90 MiB
0a147b2+dirty 49.74 MiB 55.08 MiB 5.34 MiB
d7d54c6+dirty 49.74 MiB 55.09 MiB 5.34 MiB
c823bb5+dirty 48.30 MiB 53.58 MiB 5.28 MiB
5789645+dirty 49.74 MiB 54.85 MiB 5.11 MiB
40c9884+dirty 49.74 MiB 55.09 MiB 5.34 MiB
d771cd5+dirty 49.74 MiB 55.36 MiB 5.62 MiB

Previous results on branch: fix/declare-optional-peer-deps

Startup times

Revision Plain With Sentry Diff
ebf349c+dirty 421.40 ms 440.63 ms 19.23 ms

App size

Revision Plain With Sentry Diff
ebf349c+dirty 50.56 MiB 56.51 MiB 5.95 MiB

@antonis
antonis marked this pull request as ready for review September 16, 2026 13:09
Comment thread CHANGELOG.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant