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

[BUG REPORT]An error occurred when using with nuxt-icon. #462

Closed
yongho0605 opened this issue Dec 13, 2023 · 4 comments
Closed

[BUG REPORT]An error occurred when using with nuxt-icon. #462

yongho0605 opened this issue Dec 13, 2023 · 4 comments

Comments

@yongho0605
Copy link

OS: macOS latest
Browser: chrome latest
node version: 20.9.0
Nuxt version: 3.8.1
nuxt-icon version: 0.6.6
@nuxtjs/storybook version: 7.0.0

how can i do?

I've tried many times to disable the vite plugin, but failed to clear the error

스크린샷 2023-12-13 오전 11 01 02

스크린샷 2023-12-13 오전 11 01 13

@yongho0605 yongho0605 changed the title An error occurred when using with nuxt-icon. [BUG REPORT]An error occurred when using with nuxt-icon. Dec 13, 2023
@alexcroox
Copy link

Did you find a way around this?

@cain
Copy link

cain commented May 29, 2024

Same error i have, fresh nuxt project

@sbloska
Copy link

sbloska commented Jun 12, 2024

I've got around this problem by copying the nuxt icon component into my repo. Its not the most elegant solution but it works as a temporary work around

// components/NuxtIcon.vue
<template>
  <span
    class="nuxt-icon"
    :class="{
      'nuxt-icon--fill': !filled,
      'nuxt-icon--stroke': hasStroke && !filled
    }"
    v-html="icon"
  />
</template>

<script setup lang="ts">
const props = withDefaults(
  defineProps<{
    name: string
    filled?: boolean
  }>(),
  { filled: false }
)

const icon = ref<string | Record<string, any>>('')
let hasStroke = false

async function getIcon() {
  try {
    const iconsImport = import.meta.glob('assets/icons/**/**.svg', {
      as: 'raw',
      eager: false
    })
    const rawIcon = await iconsImport[`/assets/icons/${props.name}.svg`]()
    if (rawIcon.includes('stroke')) {
      hasStroke = true
    }
    icon.value = rawIcon
  } catch {
    console.error(
      `[nuxt-icons] Icon '${props.name}' doesn't exist in 'assets/icons'`
    )
  }
}

await getIcon()

watchEffect(getIcon)
</script>

<style>
.nuxt-icon svg {
  width: 1em;
  height: 1em;
  margin-bottom: 0.125em;
  vertical-align: middle;
}
.nuxt-icon.nuxt-icon--fill,
.nuxt-icon.nuxt-icon--fill * {
  fill: currentColor !important;
}

.nuxt-icon.nuxt-icon--stroke,
.nuxt-icon.nuxt-icon--stroke * {
  stroke: currentColor !important;
}
</style>

@tobiasdiez
Copy link
Collaborator

This should be fixed in the next version (i.e. in the main branch).

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

5 participants