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

Vue3/Vite auto importing icon names with sequential dashed numbers results in mangled filename #317

Open
5 tasks done
bbugh opened this issue Oct 19, 2023 · 15 comments
Open
5 tasks done

Comments

@bbugh
Copy link

bbugh commented Oct 19, 2023

Describe the bug

After looking at the code for a while, I'm fairly certain it's caused by one of the name resolvers converting the component name into camel case and then at some point the name is converted back to kebab.

I dug through the code for a while see where this is happening and I couldn't find the source; everywhere I looked it was already converted to camel case.


For example, when importing

<i-fluent-speaker-2-24-regular />

An error is thrown:

Icon `fluent/speaker224-regular` not found

This should be fluent/speaker-2-24-regular.


Importing via direct import works fine:

<script setup>
import FluentSpeaker224Regular from 'virtual:icons/fluent/speaker-2-24-regular'
</script>

<template>
  <FluentSpeaker224Regular />
</template>

Reproduction

https://stackblitz.com/edit/vue3-script-setup-with-vite-fasbhc?file=src%2FApp.vue,vite.config.js

System Info

sh: envinfo: command not found

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@stackblitz
Copy link

stackblitz bot commented Oct 19, 2023

@userquin
Copy link
Member

it seems another problem, we're using camelToKebab and the resolver should be fine:

imagen

@bbugh
Copy link
Author

bbugh commented Oct 19, 2023

Hey @userquin. Your example shows you accidentally passing kebab case in to camelToKebab. If you pass the actual camel case in, you can see the issue reproduced.

image

I don't believe the problem is the conversion back from camel case, it's the conversion from kebab case to camel case. It is losing precision in the conversion process because camelCase doesn't have a separator that can delimit sequential numbers.

image

@olemarius
Copy link

I just upgraded from 0.16.5 to 1.17.1 and got errors for any icons containing : such as

<icon-heroicons-outline:terminal

[unplugin-icons] Could not load ~icons/heroicons/terminal (imported by src/components/mycomponent.vue?vue&type=script&setup=true&lang.ts): Icon heroicons/terminal not found
@bloc/frontend:preview: error during build:

@userquin
Copy link
Member

userquin commented Oct 31, 2023

@olemarius can you fork this SB repro https://stackblitz.com/fork/github/unplugin/unplugin-icons/tree/userquin/docs-add-stackblitz-links/examples/vite-vue3 and add a reproduction?

EDIT: I guess we also need to fix the compiler.

@olemarius
Copy link

@olemarius can you fork this SB repro https://stackblitz.com/fork/github/unplugin/unplugin-icons/tree/userquin/docs-add-stackblitz-links/examples/vite-vue3 and add a reproduction?

EDIT: I guess we also need to fix the compiler.

Thanks, managed to track down what caused it. Seems to be the componentPrefix: 'icon', option here:

https://stackblitz.com/edit/unplugin-unplugin-icons-8kzqtn?file=vite.config.ts

@userquin
Copy link
Member

@olemarius you've installed heroicons, install heroicons-outline instead

imagen

or use icon-heroicons:command-line:

imagen

In the meantime, import the icon manually: https://stackblitz.com/edit/unplugin-unplugin-icons-g3be2f?file=App.vue

@userquin
Copy link
Member

userquin commented Oct 31, 2023

it seems a problem with unplugin-vue-components and/or unplugin-auto-import

@olemarius
Copy link

Yea I can always apply a refactor/workaround to fix the problem, but it's a huge project where we use a lot of different icons and they've worked fine before. So I wouldn't expect regressions from upgrading unplugin-icons. To me it seems like the rewrite of : to - is somehow not playing nicely when the componentPrefix option is used.

@userquin
Copy link
Member

userquin commented Nov 1, 2023

@olemarius I'll try to fix the problem, or add an option to enable old : behavior if cannot be fixed here

@bbugh
Copy link
Author

bbugh commented Nov 1, 2023

I'm confused about this thread as it doesn't seem like the conversation happening now is related at all to the original issue I reported above.

@userquin
Copy link
Member

userquin commented Nov 1, 2023

@bbugh upps, you're right, checking your use case... I'll remove this issue from the PR

@userquin
Copy link
Member

userquin commented Nov 1, 2023

@bbugh it seems a problem with unplugin-vue-components/unplugin-auto-import, adding this importPathTransform hook to the Components plugin works:

    Components({
      dts: true,
      importPathTransform(path) {
        return path === '~icons/fluent/speaker224-regular' ? '~icons/fluent/speaker2-24-regular' : path
      },
      resolvers: [
        IconsResolver({
          alias: {
            park: 'icon-park',
          },
          customCollections: ['custom', 'inline'],
        }),
      ],
    }),

imagen

@bbugh
Copy link
Author

bbugh commented Nov 3, 2023

Ahhh, thanks for the workaround! That's helpful.

@firmianaQ
Copy link

<icon-mingcute-calendar-2-line/>
Icon `mingcute/calendar2-line` not found

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