SyntaxError: unknown: Namespace tags are not supported by default

ReactjsSvg

Reactjs Problem Overview


I get the following error when trying to download svg as a React Component.

>SyntaxError: unknown: Namespace tags are not supported by default. React's JSX doesn't support namespace tags. You can turn on the 'throwIfNamespace' flag to bypass this warning.

import React from "react";
import { ReactComponent as LO } from "../a/Logo.svg"
import { NavLink } from "react-router-dom";

const Logo = () => (
  <>
    <NavLink to={"/"}>
     <LO width={"40px"} height={"40px"} />
    </NavLink>
  </>
);

export default Logo;

What is the reason ?

Reactjs Solutions


Solution 1 - Reactjs

In the SVG file, try changing:

    sketch:type TO sketchType
    xmlns:xlink TO xmlnsXlink
    xlink:href  TO xlinkHref

etc...

The idea is to create camelCase property, remember that you are working with JSX, you are not creating a string as XML does.

Solution 2 - Reactjs

Since we are in the JSX playground your SVG tags should be written as camelCase

So you can easily optimize your SVG using the link below to avoid this error :)

svgminify

Solution 3 - Reactjs

The most simple solution is to just convert the SVG file to JSX.Then create a separate component or just copy paste the tag. This website does the job perfectly.

https://svg2jsx.com/

Solution 4 - Reactjs

I had the same issue with all my svg files. Opening them in Adobe Illustrator and saving them again solved the issue.

Solution 5 - Reactjs

I recommend using svgo to compress your SVG files. Simple CLI tool that runs with NodeJS and doesn't require you to upload your copyrighted SVGs anywhere.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSilicum SiliumView Question on Stackoverflow
Solution 1 - ReactjsFrawelView Answer on Stackoverflow
Solution 2 - ReactjsAhmad SalihView Answer on Stackoverflow
Solution 3 - ReactjsTharusha JayasooriyaView Answer on Stackoverflow
Solution 4 - ReactjsBozena Z.View Answer on Stackoverflow
Solution 5 - ReactjsdevgioeleView Answer on Stackoverflow