react-native-leaflet
react-native-leaflet copied to clipboard
Issue with web simulation under expo
Hello,
I'm trying a simple example under expo.
The leaflet shows up fine when running iOS simulation. However, when I launch the web simulation, I obtain the following error:
./node_modules/react-native-leaflet-view/lib/module/LeafletView/index.js:22:7 Module not found: Can't resolve '../../android/src/main/assets/leaflet.html' 20 | 21 | const LEAFLET_HTML_SOURCE = Platform.select({
22 | ios: require('../../android/src/main/assets/leaflet.html'), | ^ 23 | android: { uri: 'file:///android_asset/leaflet.html' }, 24 | });
The example:
import { StyleSheet, Text, View, SafeAreaView } from 'react-native'; import { LatLng, LeafletView } from 'react-native-leaflet-view';
const DEFAULT_COORDINATE: LatLng = { lat: 37.78825, lng: -122.4324, };
export default function App() { return ( <SafeAreaView style={styles.root}> <LeafletView mapMarkers={[ { position: DEFAULT_COORDINATE, icon: '📍', size: [32, 32], }, ]} mapCenterPosition={DEFAULT_COORDINATE} /> </SafeAreaView>); }
const styles = StyleSheet.create({ root: { flex: 1, justifyContent: 'center', alignItems: 'center', }, });
I have the same issue with my react-native-web based project. My stack:
- native-base 3.2.2
- react-native-web 0.17.5
- next 12.0.4
- firefox 96.0.3
- macos 12.1
- macbook air 2019
Here is my investigation so far:
When react-native-leaflet is installed, android/src/main/assets/leaflet.html is installed to
node_modules/react-native-leaflet-view/android/src/main/assets/leaflet.html
While src/LeafletView/index.tsx is installed to
node_modules/react-native-leaflet-view/lib/module/LeafletView/index.js
Thus src/LeafletView/index.tsx should do
✅ require('../../../android/src/main/assets/leaflet.html')
Instead of
❌ require('../../android/src/main/assets/leaflet.html')
@pavel-corsaghin Do you have an idea how to fix this? I can help send a PR.
Maybe an option for now would be to duplicate the index.html, so that expo does not do anything stupid on iOS 🤔
Maybe an option for now would be to duplicate the
index.html, so that expo does not do anything stupid on iOS 🤔
To clarify, my problem happens on macbook air, see above for my stack.
Hi is there any solution or workaround to this issue?
It would be nice to be able to write an Expo app, having leaflet work on native devices and the web :-)
Found a solution here: https://github.com/pavel-corsaghin/react-native-leaflet/issues/8#issuecomment-1435787897