-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Include a react-native
field to the package.json of various Sentry dependencies that points to ESM
#15976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey @abejfehr thanks for writing in! I think we can add such a fied but I'd like to let @krystofwoldrich chime in here. As a RN-noob, this makes me suspicious:
I'm wondering if there's something else involved because this is the first time that I'm, aware this issue is reported. Though again, Krystof probably has more insight. |
Hi @abejfehr, It makes sense to minimize the number of modules loaded at app start. I haven't tested this yet, but using the `exports' field might resolve the issue of not importing ESM. https://metrobundler.dev/docs/configuration#unstable_enablepackageexports-experimental Although marked as experimental in docs, this flag is now the default in RN 0.79 (released yesterday) |
I've tested the package exports and as expected it solves the issue of using CJS Details about the test from
|
Uh oh!
There was an error while loading. Please reload this page.
Problem Statement
Right now Sentry's modules are loaded at app start if you use
sentry-react-native
, which contains amain
field (here) that points to an ESM file ✅sentry-react-native
depends on many other Sentry packages, like the ones in this repo, and those packages do not contain amain
field orreact-native
field that points to an ESM file, theirmain
field points to a CJS file instead (like this). ❌The reason this is problematic is because virtually every RN project ever is based on Expo, and Expo's default Metro config does not prefer
module
overmain
forresolverMainFields
here.This leads to a situation where a bunch of CJS files are loaded at every app start of every Expo app, here's just an exerpt of all my loaded modules shortly after app start (obtained using this trick):
^ the number of files from
node_modules/@sentry
that are loaded on app start is 400, which is simply too many.If I manually update every
@sentry/*
package'spackage.json
to have areact-native
field that points to an ESM file, Metro transforms the ESM to CJS and inilnes the requires, which drastically reduces the number of files loaded on app start.Solution Brainstorm
Sentry packages should either inline requires when producing CJS files, or have a
react-native
field that points to ESM (even for the non-react-native packages, because those are also dependencies)The text was updated successfully, but these errors were encountered: