antfu / unplugin-icons

🤹 Access thousands of icons as components on-demand universally.

Home Page:https://www.npmjs.com/package/unplugin-icons

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug Report] broken in ESM project - Dynamic require of "@vue/compiler-sfc" is not supported

josh-hemphill opened this issue · comments

commented

In a project with "type":"module" set:

[vite-plugin-pwa] Could not load ~icons/carbon/warning (imported by src\layouts\error.vue): Dynamic require of "@vue/compiler-sfc" is not supported      
Error: Could not load ~icons/carbon/warning (imported by src\layouts\error.vue): Dynamic require of "@vue/compiler-sfc" is not supported
    at file:///C:/Users/joshua/test/node_modules/unplugin-icons/dist/chunk-QVRFTMN2.mjs:30:9
    at file:///C:/Users/joshua/test/node_modules/unplugin-icons/dist/chunk-MN45D3WG.mjs:232:77
    at async Vue3Compiler (file:///C:/Users/joshua/test/node_modules/unplugin-icons/dist/chunk-MN45D3WG.mjs:232:31
/* unplugin-icons/dist/chunk-MN45D3WG.mjs:232:77 */
// src/core/compilers/vue3.ts
var Vue3Compiler = async (svg, collection, icon) => {
  const { compileTemplate } = await Promise.resolve().then(() => __toModule(__require("@vue/compiler-sfc")));
  const { injectScripts, svg: handled } = handleSVGId(svg);
  let { code } = compileTemplate({
    source: handled,
    id: `${collection}:${icon}`,
    filename: `${collection}-${icon}.vue`
  });

@josh-hemphill can you provide a repro?

EDIT: I'm fixing it...

commented

It should be re-creatable with the default vitesse vue-3 starter template by just setting the type.

@josh-hemphill error recreated in this repo on vue3 example and fixed, creating PR...

commented

Awesome, thanks!