openmobilehub / react-native-omh-maps

https://openmobilehub.github.io/react-native-omh-maps/
Apache License 2.0
25 stars 0 forks source link

Optional plugins are required in release build on android #116

Open draggie opened 3 days ago

draggie commented 3 days ago

While using the library I have noticed that the release build on android platform is failing. My configuration does not support using the Mapbox for now and I do not reference it anywhere, although it seems to expect for this package export default require('@openmobilehub/maps-plugin-mapbox'); that is in _optionalMapboxPlugin.ts to cause such error:

error Unable to resolve module @openmobilehub/maps-plugin-mapbox from /home/runner/work/userpath/app/node_modules/@openmobilehub/maps-core/src/utils/optionalPlugins/_optionalMapboxPlugin.ts: @openmobilehub/maps-plugin-mapbox could not be found within the project or in these directories:
  node_modules
> 1 | export default require('@openmobilehub/maps-plugin-mapbox');

Since I assume there is no need to actually have all plugins configured (as they are called 'optional') I propose to modify those both optional files in such way, to solve the error:

//_optionalMapboxPlugin.ts
let mapboxPlugin;

try {
  mapboxPlugin = require('@openmobilehub/maps-plugin-mapbox');
} catch (error) {
  // Fallback or default behavior if Mapbox plugin is not installed
  console.warn('@openmobilehub/maps-plugin-mapbox is not installed');
  mapboxPlugin = null;
}

export default mapboxPlugin;
//_optionalOpenstreetmapPlugin.ts
let openStreetMapPlugin;

try {
  openStreetMapPlugin = require('@openmobilehub/maps-plugin-openstreetmap');
} catch (error) {
  console.warn('@openmobilehub/maps-plugin-openstreetmap is not installed');
  openStreetMapPlugin = null;
}

export default openStreetMapPlugin;
dzuluaga commented 3 days ago

Thanks, @draggie . Agreed, if a module isn’t declared, it shouldn’t be required unless used by default. Wrapping in a try/catch should handle it. @adamTrz , could you please look into it? @Nataliagros , please include it in the tracker. Thanks!