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

lucide-svelte not working with SvelteKit #833

Closed
bejd opened this issue Oct 22, 2022 · 7 comments
Closed

lucide-svelte not working with SvelteKit #833

bejd opened this issue Oct 22, 2022 · 7 comments
Labels
🐛 bug Something isn't working

Comments

@bejd
Copy link

bejd commented Oct 22, 2022

This may be more a feature request than a bug, so apologies if it needs to be recategorised!

Prerequisites

  • Version: 0.92.0
  • Are you running from source/main: Yes
  • Are you using a released build: Yes
  • Operating system: MacOS 12.6
  • Bits: 64

Step to reproduce

Actual behavior

Icon components work.

Any message or error

TypeError: error loading dynamically imported module client-manifest.js:20:44

<Error> was created with unknown prop 'data' client.js:1585:7

<Error> was created with unknown prop 'form' client.js:1585:7

<Root> was created without expected prop 'form' client.js:1585:7

Loading failed for the module with source “http://localhost:5173/node_modules/lucide-svelte/dist/esm/icons/accessibility.svelte?v=29d069d5”. test:135:1

Loading failed for the module with source “http://localhost:5173/node_modules/lucide-svelte/dist/esm/icons/activity.svelte?v=29d069d5”. test:135:1

... etc.

Resources

Screenshot 2022-10-22 at 12 52 28

@bejd bejd added the 🐛 bug Something isn't working label Oct 22, 2022
@JustBarnt
Copy link

@bejd I don't think is related to my issue, I am not using sveltekit, and my icons are loading, it's just loading every icon in the library compared to the two I am actually using via import.

@ericfennis
Copy link
Member

@bejd Thanks for reporting, with take a look!

@mpreu
Copy link

mpreu commented Oct 23, 2022

Confirming the issue with sveltekit. Is it possible, that vitejs/vite#8464 has relevance here? I tried the mentioned workarounds for the vite config, but does not seem to have any effect for this problem here.

I am on vite 3.1.8.

Also this seems to be a similar report for feather (or large svelte libs in general): sveltejs/kit#2612

@JustBarnt
Copy link

@mpreu From what @ericfennis found it has to do with Vites tree-shaking. It's still including the whole module.

@TheFireBlast
Copy link

I'm using this hacky workaround using svelte preprocess's replace until they fix their tree-shaking. Can't guarantee it'll work 100% of the time, but it shouldn't be too hard to add any edge cases.

replace: [
    [
        /import\s*{\s*([^}]+?)\s*,?\s*}\s*from\s+['"]lucide-svelte['"](\s*;)?/gim,
        (substring, /**@type {string} */ imports) => {
            return imports
                .split(/\s*,\s*/gim)
                .map((s) => {
                    let icon = s.split(/\s+as\s+/);
                    let name = icon[1] || icon[0];
                    let file = icon[0].replace(/[A-Z]/g, (s) => '-' + s.toLowerCase()).slice(1);
                    return `import ${name} from 'lucide-svelte/dist/esm/icons/${file}.svelte';`;
                })
                .join('');
        },
    ],
],

Result:

// From
import {
    XOctagon,
    MoreVertical,
    ArrowUpDown,
    Image as ImageIcon,
} from "lucide-svelte";
// To
import XOctagon from 'lucide-svelte/dist/esm/icons/x-octagon.svelte';
import MoreVertical from "lucide-svelte/dist/esm/icons/more-vertical.svelte";
import ArrowUpDown from "lucide-svelte/dist/esm/icons/arrow-up-down.svelte";
import ImageIcon from "lucide-svelte/dist/esm/icons/image.svelte";

@ericfennis
Copy link
Member

Created a fix in #877. Beta release is released under lucide-svelte@0.104.0-beta.6

@ericfennis
Copy link
Member

Fixed by #877

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants