maplibre / maplibre-gl-directions

A plugin to show routing directions on a MapLibre GL JS map
https://maplibre.org/maplibre-gl-directions/
MIT License
72 stars 16 forks source link

missing import in svelte prod #240

Open joleeee opened 2 weeks ago

joleeee commented 2 weeks ago

I can navigate to the page which uses this library, but if i do a refresh or type the url directly, then i get an internal server error and this is spat out:

Error: Cannot find package '/app/node_modules/@maplibre/maplibre-gl-directions/index.js' imported from /app/build/server/chunks/_page.svelte-8wkpeQkC.js
    at legacyMainResolve (node:internal/modules/esm/resolve:215:26)
    at packageResolve (node:internal/modules/esm/resolve:841:14)
    at moduleResolve (node:internal/modules/esm/resolve:927:18)
    at defaultResolve (node:internal/modules/esm/resolve:1169:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:540:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:509:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:239:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:96:40)
    at link (node:internal/modules/esm/module_job:95:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Working workaround (breaks typing!):

diff --git a/src/lib/components/map/router.ts b/src/lib/components/map/router.ts
index abdd497..1b69f8a 100644
--- a/src/lib/components/map/router.ts
+++ b/src/lib/components/map/router.ts
@@ -4,9 +4,9 @@ import type {
     Feature,
     LineString,
     Point
-} from '@maplibre/maplibre-gl-directions';
-import MapLibreGlDirections from '@maplibre/maplibre-gl-directions';
-import { MapLibreGlDirectionsWaypointEvent } from '@maplibre/maplibre-gl-directions';
+} from '../../../../node_modules/@maplibre/maplibre-gl-directions/dist/maplibre-gl-directions.js';
+import MapLibreGlDirections from '../../../../node_modules/@maplibre/maplibre-gl-directions/dist/maplibre-gl-directions.js';
+import { MapLibreGlDirectionsWaypointEvent } from '../../../../node_modules/@maplibre/maplibr
e-gl-directions/dist/maplibre-gl-directions.js';
 import { writable, type Writable } from 'svelte/store';

 export default class RouterMapLibreGlDirections extends MapLibreGlDirections {

Perhaps everything needed is an export part in the package.json? I am unable to test this because if I use a local version of the library, then I don't get the error.

This seems very relevant: https://github.com/katspaugh/wavesurfer.js/discussions/3066#discussioncomment-6719001 and https://github.com/katspaugh/wavesurfer.js/commit/2313458570066b003f4c12611448cdf6d43c2da1

Note that this bug does not occur when using npm run dev or preview for me.

smellyshovel commented 1 week ago

I've seen something similar during dev runs, which is contrary to your case:

Note that this bug does not occur when using npm run dev or preview for me.

Never payed much attention to it, as usually a simple server restart helped.

Or did I understand your issue wrong? Is there a real runtime error or something?