Sentry API does not work

@apoyando Thanks for your help I’ve been struggling with this.

You may be right. It looks like my App.js imports both my NativeApp and my WebApp and then conditionally exports the right one based on what Platform.OS says. Is there a way to have two different entry points?

I also have this strange line in it. Not sure why… might be related?
export * from './src/src/App';
(which is my native app)

Full code:

import NativeApp from './src/src/App';
import WebApp from './src/src/web/App';
import { Platform } from 'react-native';

let app = NativeApp as any;
if (Platform.OS === 'web') {
  app = WebApp;
}
export default app;
export * from './src/src/App';

@vjsingh If you’re always exporting * from your native app entry, you’re always going to get your Sentry initialization from there.

If your web app actually needs exports from what is now your native app entry, then you might want to rethink the way you’ve structured your project. If not, then the “export *” is at best unnecessary.

Again, the web vs native logic you’re using could be replaced by using platform-specific files. You could simply import app from './App' in the file you quote above, and then create App.native.js and App.web.js files to import the right entries from the right directories.

1 Like

@apoyando Thanks so much! This is actually a huge help for us. I’ve wasted countless hours dealing with issues where my web project wouldn’t compile because of an import that was only in my native code.

I won’t have time to look at this until next week but it looks like it should work.

@charliecruzan I can’t find any mention of the app.native.js and app.web.js files in the Expo documentation. Did I miss it, or if not would it be worth adding?

@vjsingh This is the documentation you need: https://docs.expo.io/versions/v35.0.0/react-native/platform-specific-code/

2 Likes

@apoyando there it is, thanks! Also sorry for hijacking this thread :zipper_mouth_face:

@apoyando Thanks for the info - I set up my entry points in the way you described, and now don’t get compile time issues for unused files.

The only remaining issue is that Typescript doesn’t seem to understand the “.web.tsx” and “.native.tsx” extensions.

Is there a way around this? Found these two related issues:


This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.