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

Failed to resolve entry for package "@maplibre/maplibre-gl-directions". The package may have incorrect main/module/exports specified in its package.json. #246

Open
chanmathew opened this issue Jan 3, 2025 · 4 comments

Comments

@chanmathew
Copy link

Hi there,

I'm trying to install this library in a Sveltekit project, and I'm getting the following errors:

Error: Failed to resolve entry for package "@maplibre/maplibre-gl-directions". The package may have incorrect main/module/exports specified in its package.json.

Here are my relevant packages:

"svelte-maplibre": "v1.0.0-next.8",
"@sveltejs/adapter-auto": "3.2.4",
"@sveltejs/kit": "2.15.1",
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"rollup-plugin-visualizer": "5.12.0",
"svelte": "5.16.0",
"svelte-check": "4.0.5",
"typescript": "5.5.4",
"vite": "6.0.3"

Not sure what the issue is exactly 🤔

@smellyshovel
Copy link
Collaborator

Hi, @chanmathew! Would be really helpful to see at least some minimal reproduction here.
Are you installing the plugin as a local package? Or straight from NPM?

@chanmathew
Copy link
Author

chanmathew commented Jan 3, 2025

Hi @smellyshovel - here you go. I'm installing as npm package:

https://stackblitz.com/edit/sveltejs-kit-template-default-6qckztah?file=src%2Froutes%2F%2Bpage.svelte

You can see as soon as I add the import from the lib it breaks the app, if you remove the import the app loads fine again.

@smellyshovel
Copy link
Collaborator

Hi @smellyshovel - here you go. I'm installing as npm package:

https://stackblitz.com/edit/sveltejs-kit-template-default-6qckztah?file=src%2Froutes%2F%2Bpage.svelte

You can see as soon as I add the import from the lib it breaks the app, if you remove the import the app loads fine again.

From what I can see, it's really an issue with plugin's settings. In short (and if I'm not mistaken), I'm using a set of package.json's fields which are compatible with earlier versions of Vite, but the newer ones need some other set of fields.

I'll try to fix that ASAP and will let you know when a new version is available. Thanks for letting me know and creating a repro!

smellyshovel added a commit that referenced this issue Jan 4, 2025
…the relevant declarations to the top of the file)
@smellyshovel
Copy link
Collaborator

@chanmathew I created a PR as an attempt to fix the issue.

It may not work though. And, in short, even though I have another way to try to fix it, this other way would require a lot of work to do.

So, meanwhile the PR is being reviewed and a new version is being released, you can try the following fix (in vite.config.js):

resolve: {
    alias: {
      '@maplibre/maplibre-gl-directions': '/node_modules/@maplibre/maplibre-gl-directions/dist/maplibre-gl-directions.js',
    },
  },
  optimizeDeps: {
    include: ['@maplibre/maplibre-gl-directions'],
  },

Please, tell me if this works for you (but try it locally, not on StackBlitz, as it's not clear how they handle dependency paths there).

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

2 participants