{"id":14084,"library":"svg-to-vue","title":"SVG to Vue Component Converter","description":"svg-to-vue is a utility designed to convert raw SVG code directly into a Vue component definition. It currently resides at version 0.7.0. While no explicit release cadence is published, it functions as a stable tool for its specific purpose. Its core differentiator is simplifying the integration of arbitrary SVG strings into Vue 2.x applications as programmatically generated components, with optional built-in SVGO optimization to reduce SVG file size and improve performance. This makes it particularly useful for dynamically rendering SVG content or when SVGs are sourced from external APIs or user input, rather than being static assets. It explicitly depends on Vue 2.x's `vue-template-compiler` for its functionality, making it incompatible with Vue 3.x.","status":"active","version":"0.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/visualfanatic/svg-to-vue","tags":["javascript","vue","svg","svgo"],"install":[{"cmd":"npm install svg-to-vue","lang":"bash","label":"npm"},{"cmd":"yarn add svg-to-vue","lang":"bash","label":"yarn"},{"cmd":"pnpm add svg-to-vue","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for compiling Vue 2.x templates from the generated component definition. It is a peer dependency and must be installed separately.","package":"vue-template-compiler","optional":false}],"imports":[{"note":"This package is primarily designed for CommonJS environments and exports a single function. Direct ESM import may not work as expected without proper module interoperability configuration in tools like TypeScript or Babel.","wrong":"import svgToVue from 'svg-to-vue';","symbol":"svgToVue","correct":"const svgToVue = require('svg-to-vue');"}],"quickstart":{"code":"const svgToVue = require('svg-to-vue');\n\nconst svgCode = `\n  <svg width=\"300\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\">\n    <rect width=\"100%\" height=\"100%\" fill=\"red\" />\n    <circle cx=\"150\" cy=\"100\" r=\"50\" fill=\"blue\" />\n    <text x=\"150\" y=\"100\" font-family=\"sans-serif\" font-size=\"20\" fill=\"white\" text-anchor=\"middle\" alignment-baseline=\"middle\">Hello SVG!</text>\n  </svg>\n`;\n\nsvgToVue(svgCode, {\n  svgoConfig: {\n    plugins: [\n      { name: 'preset-default' },\n      { name: 'prefixIds', params: { prefix: 'my-unique-svg-id-' } }\n    ]\n  },\n  svgoPath: 'dynamic-svg-component'\n})\n  .then((componentDefinition) => {\n    // `componentDefinition` contains a Vue component object\n    // that can be registered globally or locally in a Vue 2.x app.\n    console.log('Vue Component Definition:', componentDefinition);\n    // Example: To use in a Vue app (assuming Vue is available):\n    // new Vue({\n    //   el: '#app',\n    //   components: { MyDynamicSVG: componentDefinition },\n    //   template: '<div id=\"app\"><MyDynamicSVG /></div>'\n    // });\n  })\n  .catch(error => {\n    console.error('Error converting SVG:', error);\n  });","lang":"javascript","description":"This quickstart converts a basic SVG string into a Vue 2.x component definition, including SVGO optimization and ID prefixing, then logs the resulting component object."},"warnings":[{"fix":"Use this package only within Vue 2.x environments. For Vue 3.x, explore alternative solutions like `vite-plugin-svg-component` or manually importing SVG as components.","message":"The package explicitly relies on `vue-template-compiler`, which is a dependency for Vue 2.x. It is not compatible with Vue 3.x applications and will likely fail to generate valid components or lead to runtime errors.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Always install `vue-template-compiler` alongside `svg-to-vue`: `npm i svg-to-vue vue-template-compiler` or `yarn add svg-to-vue vue-template-compiler`.","message":"Missing `vue-template-compiler` can lead to runtime errors. Although it's a peer dependency, the installation instructions explicitly state it's required, meaning it won't be automatically installed by `svg-to-vue`.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always provide a unique string for the `svgoPath` option (e.g., a file path or a unique component identifier) when using SVGO's `prefixIds` plugin to ensure consistent and unique IDs across your application.","message":"The `svgoPath` option is crucial for correct ID generation when using SVGO's `prefixIds` plugin. If `prefixIds` is enabled in `svgoConfig` but `svgoPath` is null or not unique, it can lead to non-unique IDs in the rendered SVG, causing rendering issues, styling conflicts, or accessibility problems if multiple generated components are on the same page.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Evaluate migration to Vue 3.x and its associated SVG handling methods for long-term project viability. Continue using `svg-to-vue` only if locked into a Vue 2.x project.","message":"The `vue-template-compiler` (and by extension, this utility) is tied to the end-of-life Vue 2 ecosystem. While functional, active development and new features for Vue 2-dependent tools are minimal.","severity":"deprecated","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.7.0':30 '2':61,114 '3':129 'api':100 'applic':63 'arbitrari':56 'asset':108 'built':71 'built-in':70 'cadenc':35 'code':18 'compil':120 'compon':4,23,67 'content':92 'convert':5,15 'core':49 'current':26 'definit':24 'depend':111 'design':13 'differenti':50 'direct':19 'dynam':89 'explicit':33,110 'extern':99 'file':78 'function':39,123 'generat':66 'improv':81 'incompat':126 'input':103 'integr':54 'javascript':131 'make':84,124 'optim':74 'option':69 'particular':86 'perform':82 'programmat':65 'publish':37 'purpos':47 'rather':104 'raw':16 'reduc':76 'releas':34 'render':90 'resid':27 'simplifi':52 'size':79 'sourc':97 'specif':46 'stabl':42 'static':107 'string':58 'svg':1,7,17,57,77,91,133 'svg-to-vu':6 'svgo':73,134 'svgs':95 'templat':119 'tool':43 'use':87 'user':102 'util':12 'version':29 'vue':3,9,22,60,113,118,128,132 'vue-template-compil':117 'x':62,115,130","created_at":"2026-04-20T01:57:51.078263+00:00","updated_at":"2026-04-20T01:57:51.078263+00:00","problems":[{"fix":"Install the missing dependency: `npm install vue-template-compiler` or `yarn add vue-template-compiler`.","cause":"The `vue-template-compiler` package is a peer dependency but was not installed alongside `svg-to-vue`.","error":"Error: Cannot find module 'vue-template-compiler' from '[path to svg-to-vue]'"},{"fix":"Use the CommonJS `require` syntax: `const svgToVue = require('svg-to-vue');`. If using TypeScript, ensure `esModuleInterop: true` and `allowSyntheticDefaultImports: true` are enabled in `tsconfig.json`.","cause":"This error occurs when attempting to use ESM `import` syntax (e.g., `import svgToVue from 'svg-to-vue'`) on a CommonJS-only package in environments that don't correctly handle synthetic default imports or when the package doesn't provide a named default export.","error":"TypeError: (0 , _svg_to_vue__WEBPACK_IMPORTED_MODULE_0__.default) is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"svg-to-vue","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/visualfanatic/svg-to-vue","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/svg-to-vue","openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}