[vite] Internal server error: Cannot read property ‘replace‘ of undefined vite-plugin-svg-icons

陆昊
2023-12-01

[vite] Internal server error: Cannot read property ‘replace’ of undefined
issue
npm run dev

4:28:57 [vite] Internal server error: Cannot read property ‘replace’ of undefined
at compilerIcon (D:\proj\springBoot\vue3-mooding-boot2\mooding-boot-vue\node_modules_vite-plugin-svg-icons@1.1.0@vite-plugin-svg-icons\dist\index.js:5320:21)
at async getSymbol (D:\proj\springBoot\vue3-mooding-boot2\mooding-boot-vue\node_modules_vite-plugin-svg-icons@1.1.0@vite-plugin-svg-icons\dist\index.js:5282:21)
at async compilerIcons (D:\proj\springBoot\vue3-mooding-boot2\mooding-boot-vue\node_modules_vite-plugin-svg-icons@1.1.0@vite-plugin-svg-icons\dist\index.js:5294:9)
at async createModuleCode (D:\proj\springBoot\vue3-mooding-boot2\mooding-boot-vue\node_modules_vite-plugin-svg-icons@1.1.0@vite-plugin-svg-icons\dist\index.js:5233:33)
at async Context.load (D:\proj\springBoot\vue3-mooding-boot2\mooding-boot-vue\node_modules_vite-plugin-svg-icons@1.1.0@vite-plugin-svg-icons\dist\index.js:5203:31)
at async Object.load (D:\proj\springBoot\vue3-mooding-boot2\mooding-boot-vue\node_modules_vite@2.9.15@vite\dist\node\chunks\dep-689425f3.js:39293:32)
at async doTransform (D:\proj\springBoot\vue3-mooding-boot2\mooding-boot-vue\node_modules_vite@2.9.15@vite\dist\node\chunks\dep-689425f3.js:49982:24)

async function compilerIcon(file, symbolId, svgOptions) {
  if (!file) {
    return null;
  }
  let content = import_fs_extra.default.readFileSync(file, "utf-8");
  if (svgOptions) {
    const { data } = await (0, import_svgo.optimize)(content, svgOptions);
    console.log("content");
    console.log(content);
    console.log("svgOptions");
    console.log(svgOptions);
    content = data;
  }
  content = content.replace(/stroke="[a-zA-Z#0-9]*"/, 'stroke="currentColor"');
  const svgSymbol = await new import_svg_baker.default().addSymbol({
    id: symbolId,
    content,
    path: file
  });

ontent

<?xml version="1.0" standalone="no"?>

svgOptions
{}

解决
cnpm i -D vite-plugin-svg-icons@1.0.5

 类似资料: