bemky / mapbox-gl-draw-freehand-mode

Mode for Mapbox GL Draw that simplifies UI to only free drawing
https://github.com/mapbox/mapbox-gl-draw
ISC License
69 stars 41 forks source link

Cannot find module #27

Open PerryRylance opened 8 months ago

PerryRylance commented 8 months ago

I've been using this for a while in a React build without issue, but when I try to use it inside Angular, we're seeing this

Error: Module not found: Error: Can't resolve '@mapbox/mapbox-gl-draw/src/modes/draw_polygon'

Error: Module not found: Error: Can't resolve '@mapbox/mapbox-gl-draw/src/constants'

This seems to be correct in that there is no /src directory, but that doesn't bother the React build.

I can see there are related issues that were opened and then closed again, if someone could point me to a solution that would be great. I can see folks have had similar issues but with no solution posted in the closed issues.

PerryRylance commented 7 months ago

We ended up using patch-package to alter this slightly, works well.

campbell-r commented 7 months ago

What were the code changes you patched?

basaran commented 6 months ago

@PerryRylance , are you able to use this with maplibregl? It kind of works but I'm getting a TypeError: Cannot read properties of null (reading '0').

PerryRylance commented 6 months ago

I haven't tried with maplibregl, sorry.

Here's the patch we used:

diff --git a/node_modules/mapbox-gl-draw-freehand-mode/src/index.js b/node_modules/mapbox-gl-draw-freehand-mode/src/index.js
index 7af9ee5..ea19eb5 100644
--- a/node_modules/mapbox-gl-draw-freehand-mode/src/index.js
+++ b/node_modules/mapbox-gl-draw-freehand-mode/src/index.js
@@ -1,8 +1,16 @@
-import DrawPolygon from '@mapbox/mapbox-gl-draw/src/modes/draw_polygon';
-import {geojsonTypes, cursors, types, updateActions, modes, events} from '@mapbox/mapbox-gl-draw/src/constants';
+import MapboxGlDraw from '@mapbox/mapbox-gl-draw';
 import simplify from "@turf/simplify";

-const FreehandMode = Object.assign({}, DrawPolygon)
+const {
+   geojsonTypes,
+   cursors,
+   types,
+   updateActions,
+   modes,
+   events,
+} = MapboxGlDraw.constants;
+
+const FreehandMode = Object.assign({}, MapboxGlDraw.modes.draw_polygon);

 FreehandMode.onSetup = function() {
     const polygon = this.newFeature({