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

Add support vitejs (ESM) #6

Closed
Rysakov1986 opened this issue Jun 16, 2021 · 9 comments · Fixed by #35
Closed

Add support vitejs (ESM) #6

Rysakov1986 opened this issue Jun 16, 2021 · 9 comments · Fixed by #35

Comments

@Rysakov1986
Copy link

Help, i have error:
Uncaught SyntaxError: The requested module '/node_modules/leaflet/dist/leaflet-src.js?v=8128ddc4' does not provide an export named 'default'

@ngyewch
Copy link
Owner

ngyewch commented Jun 17, 2021

Sorry, I have no experience with vitejs.

I have played with snowpack, but what I find is that different frontend tooling have their own problems.

@benbabics
Copy link

@Rysakov1986 did you ever end up getting this to work? I'd like to use this for a project, but I'm getting the same error and @ngyewch answer doesn't really help or give me much hope. It looks as if it's an active project though.

@0gust1
Copy link

0gust1 commented Dec 6, 2021

Using this trick #3 (comment), I was able to run it OK on a svelte-kit project (which is powered by Vite).

Since this summer, there was a lot of improvement on Vite's side to handle the different module flavors (CJS, ESM, UMD, etc.). I'm personally very impatient that the ecosystem will be mainly ESM-only (this topic is such a pain to handle !)

@timwis
Copy link

timwis commented Feb 9, 2022

The error sounds like you're doing:

import LeafletMap from 'svelte-leafletjs'

That should use the library's default export, but package.json points vite to the dist directory, and those files don't seem to have a default export. Maybe rollup needs to create an ESM-import-friendly build?

Anyway, try importing the named exports, e.g.

import { LeafletMap, TileLayer } from 'svelte-leafletjs'

@DrewRidley
Copy link

DrewRidley commented Dec 26, 2022

The library still does not work even when following that guide.
I get the following error:

svelte-leaflet doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.

@DrewRidley
Copy link

Nevermind, it seems that I had a second import that was not using the ?client directive. This method still works as far as I am aware.

@notramo
Copy link

notramo commented May 16, 2023

@ngyewch, as the Svelte ecosystem moved mainly to using Vite as build tool, could you revisit this issue?

@ngyewch
Copy link
Owner

ngyewch commented May 17, 2023

@notramo Yeah, I have moved to Vite for other Svelte projects. I just have to find some time to migrate this project. Hopefully in the near future.

@jieter
Copy link
Contributor

jieter commented Jan 19, 2024

A basic vite svelte project with svelte-leafletjs works fine, it only emits this warning:

10:00:47 AM [vite-plugin-svelte] WARNING: The following packages have a svelte field in their package.json but no exports condition for svelte.

[email protected]

Please see https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#missing-exports-condition for details.

Quoting the link:

missing exports condition

If you see a warning logged for this when using a Svelte library, please tell the library maintainers.

Using the svelte field in package.json to point at .svelte source files is deprecated and you must use a svelte export condition.
vite-plugin-svelte 3 still resolves it as a fallback, but in a future major release this is going to be removed and without exports condition resolving the library is going to fail.

Example:

// package.json
  "files": ["dist"],
  "svelte": "dist/index.js",
+ "exports": {
+   ".": {
+     "svelte": "./dist/index.js"
+   }
  }

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

Successfully merging a pull request may close this issue.

8 participants