Skip to content

Error loading metro config: Cannot find module 'tslib' #4562

@DaniFoldi

Description

@DaniFoldi

What React Native libraries do you use?

React Navigation, Expo (mobile only), Expo Application Services (EAS)

Are you using sentry.io or on-premise?

sentry.io (SaS)

@sentry/react-native SDK Version

6.6.0

How does your development environment look like?

OS: macOS 15.3
Node: 22.11.0
Expo: 52.0.35
react: 18.3.1
react-native: 0.77.0

although I think what is more relevant: we use pnpm for package manager, and it's set up as a workspace.
The app lives in /packages/app.

Sentry.init()

Sentry.init({
  dsn: constants.expoConfig?.extra?.sentry?.dsn,
  attachStacktrace: true,
  enableTracing: true,
  tracesSampleRate: 1,
  sampleRate: 1,
  debug: __DEV__,
  integrations: [
    Sentry.httpClientIntegration(),
    Sentry.reactNativeInfoIntegration()
  ]
})

Steps to Reproduce

  1. create a pnpm workspace, with an expo app in say /packages/app - make sure hoisting is disabled
  2. add sentry
  3. observe that while building, the error below is thrown.

The reason (I suspect) is that tslib is not declared as a dependency, but somehow ends up in the built file dist/js/tools/metroconfig.js (and others, but this is the first one to be found by the build process).

Expected Result

tslib is depended upon, and therefore found while importing it

Actual Result

ERROR: Error loading .../packages/app/metro.config.cjs
Reason: Cannot find module 'tslib'
Require stack:
- .../node_modules/.pnpm/@[email protected][email protected]_@[email protected]_@[email protected]_@babel+co_r4te4muu5h7i3sl6odqu22xk5u/node_modules/@sentry/react-native/dist/js/tools/metroconfig.js

Metadata

Metadata

Labels

Projects

Status

Done

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions