question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

πŸ› SVG <defs>, <symbol> and <use> are unsupported in parcel build

See original GitHub issue

πŸ› bug report support SVG <defs>, <symbol> and <use> in HTML

πŸ€” Expected Behavior

SVG <defs>, <symbol> and <use> tags to be present in the output minified html file.

😯 Current Behavior

Ive been able to consistently reproduce the problem in one index.html file:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <svg xmlns="http://www.w3.org/2000/svg">
      <defs>
        <g id="circle">
          <circle cx="100" cy="100" r="100"/>
        </g>
      </defs>
    </svg>
    <div id="app">
      <svg style="display:block;margin:0 auto;" height="250px">
        <use xlink:href='#circle' href='#circle'/>
      </svg>
    </div>
  </body>
</html>

run: parcel build index.html

output:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <svg xmlns="http://www.w3.org/2000/svg"/> <div id="app"> undefined </div> </body> </html> 

The <defs> tag disappears and <use> tag is replaced with undefined. Note that I use xlink:href as href is not supported in Safari 11

πŸ’ Possible Solution

Using <svg> works and is transpiled correctly. I could omit the use of <defs> and move the entire <svg> content to all the places I have the <use> tag. Sadly, as you’ll notice, that’ll mean having repeated svgs which <defs> were created to solve.

πŸ”¦ Context

I define my re-usable svgs in <defs> or <symbol> in index.html and use them throughout my application.

🌍 Your Environment

Software Version(s)
Parcel 1.5.1
Node 9.4.0
npm 5.6.0
Operating System macOS High Sierra
Browsers Safari 11.0.1, Chrome 63.0.3239.132

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

13reactions
davidenkecommented, May 8, 2018

@alyssaq after a quick research at the specs it looks like both attributes are required xmlns and xmlns:xlink at the svg element.

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
>
    <use xlink:href="assets/sprite.svg#icon"></use>
</svg>

Now my IDE (IntelliJ) shows no more warnings.

9reactions
alyssaqcommented, Jan 30, 2018

Ha, its my fault. I ran each snippet of the svg in svgo and got this error: { error: 'Error in parsing SVG: Unbound namespace prefix: "xlink"\nLine: 0\nColumn: 98\nChar: >' }

I added the xlink prefix to the svg tag:

<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="display:block;margin:0 auto;" >
     <use xlink:href='#circle' href='#circle'/>
</svg>

parcel build index.html correctly outputted the svg!

Learnt something new about svg.
Thanks for responding so quickly. πŸ˜„

Read more comments on GitHub >

github_iconTop Results From Across the Web

SVG - Parcel
SVG is a vector-based 2D graphics format based on XML, with support for interactivity and animation. Parcel includes support for SVG as a...
Read more >
@svgr/cli | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
rollup.js
Rollup allows you to write your code using the new module system, and will then compile it back down to existing supported formats...
Read more >
SVG icons are cut from website when bundle with parcel@2.0 ...
I have a small problem, I'm building a project using html, scss, parcel, for bundling and for scss transformer to css, svg icons....
Read more >
SVG tile format | Google Maps Tile API - Google Developers
When to not use SVG files; Get SVG format tile images; SVG XML; SVG XML Usage ... Note: scale and highDpi are unsupported...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found