Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module #27

Open
PerryRylance opened this issue Jan 24, 2024 · 5 comments
Open

Cannot find module #27

PerryRylance opened this issue Jan 24, 2024 · 5 comments

Comments

@PerryRylance
Copy link

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
Copy link
Author

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

@campbell-r
Copy link

What were the code changes you patched?

@basaran
Copy link

basaran commented Mar 1, 2024

@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
Copy link
Author

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

@aakash-pl
Copy link

aakash-pl commented Oct 18, 2024

@PerryRylance Thank you for the patch. I just had one question. In this piece of code, what did you replace DrawPolygon with ?

FreehandMode.onStop = function (state) { DrawPolygon.call(this, state) setTimeout(() => { if (!this.map || !this.map.dragPan) return; this.map.dragPan.enable(); }, 0); };

_Uncaught TypeError: mapbox_mapbox_gl_draw__WEBPACK_IMPORTED_MODULE_0___default(...).modes.draw_polygon.call is not a function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants