mapbox-gl-draw-freehand-mode
mapbox-gl-draw-freehand-mode copied to clipboard
Cannot find module
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.
We ended up using patch-package
to alter this slightly, works well.
What were the code changes you patched?
@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')
.
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({