mapbox-gl-draw-freehand-mode icon indicating copy to clipboard operation
mapbox-gl-draw-freehand-mode copied to clipboard

Cannot find module

Open PerryRylance opened this issue 1 year ago • 5 comments

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 avatar Jan 24 '24 11:01 PerryRylance

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

PerryRylance avatar Jan 27 '24 13:01 PerryRylance

What were the code changes you patched?

campbell-r avatar Feb 21 '24 18:02 campbell-r

@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').

basaran avatar Mar 01 '24 23:03 basaran

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({

PerryRylance avatar Mar 04 '24 07:03 PerryRylance