Skip to content
This repository has been archived by the owner on Nov 18, 2023. It is now read-only.

Iconify.renderSVG is not a function #14

Open
dnldsht opened this issue Feb 16, 2021 · 1 comment
Open

Iconify.renderSVG is not a function #14

dnldsht opened this issue Feb 16, 2021 · 1 comment

Comments

@dnldsht
Copy link

dnldsht commented Feb 16, 2021

Screenshot 2021-02-16 at 10 03 33 AM

The first time I start a nuxt project I get this error, after one or more hot reloads it get fixed.

import Iconify from '@purge-icons/generated'

When the error occurs Iconify is an empty object.

This is my Icon component:

<template>
  <div ref="el" :class="$attrs.class" style="vertical-align: text-bottom" />
</template>

<script lang="js">
import Iconify from '@purge-icons/generated'

export default {
  props: {
    icon: {
      type: String,
      required: true,
    },
  },
  watch: {
    icon: {
      handler() {
        this.update()
      },
      immediate: true,
    },
  },
  methods: {
    update() {
      this.$nextTick(async() => {
        const el = this.$refs.el
        if (el) {
          // console.log(Iconify);
          const svg = Iconify.renderSVG(this.icon, {})
          if (svg) {
            el.textContent = ''
            el.appendChild(svg)
          }
          else {
            const span = document.createElement('span')
            span.className = 'iconify'
            span.dataset.icon = this.icon
            el.textContent = ''
            el.appendChild(span)
          }
        }
      })
    },
  },
}
</script>

I've only added this to nuxt.config.js

buildModules: [
    // https://go.nuxtjs.dev/vuetify
    '@nuxtjs/vuetify',
    'nuxt-purge-icons-module'
  ],

Here you can find a repo with the issue that only has nuxt, vuetify and purge icons

@antfu
Copy link
Owner

antfu commented Feb 22, 2021

I am not very sure why but as a workaround, you can do this and it will work the same:

<script lang="js">
import Iconify from '@iconify/iconify'
import '@purge-icons/generated'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants