Svgr: React Native: JSX namespace error thrown

Created on 29 Jan 2019  路  10Comments  路  Source: gregberge/svgr

馃悰 Bug Report

Bug when rendering this file: ember.svg

I have created an SVG transformer for React Native.

When I use svgr to render the images inside the transformer file, React Native throws an error during the transform:

SyntaxError: /Users/kristerkari/Git/SVGDemo/logos/ember.svg: 
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.

This happens because of the xmlns:svg="http://www.w3.org/2000/svg" attribute on the ember.svg image. If I remove that attribute, then the error is not thrown. The svg->svgr transform should probably take of that.

Link to repl or repo (highly encouraged)

App that I use for testing: https://github.com/kristerkari/react-native-svg-example
Images that I want to render: https://github.com/kristerkari/react-native-svg-example/tree/master/logos

Run npx envinfo --system --binaries --npmPackages @svgr/core,@svgr/cli,@svgr/webpack,@svgr/rollup --markdown --clipboard

Paste the results here:

## System:
 - OS: macOS High Sierra 10.13.6
 - CPU: x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
 - Memory: 675.03 MB / 16.00 GB
 - Shell: 2.7.1 - /usr/local/bin/fish
## Binaries:
 - Node: 8.11.4 - /usr/local/bin/node
 - Yarn: 1.12.1 - /usr/local/bin/yarn
 - npm: 6.4.0 - /usr/local/bin/npm
 - Watchman: 4.9.0 - /usr/local/bin/watchman
## npmPackages:
 - @svgr/core: ^4.0.3 => 4.0.3 
 - @svgr/webpack: ^4.0.0 => 4.0.0 
bug 馃悰 good first issue 馃 help wanted 馃啒

Most helpful comment

Also happens when dealing with inkscape svgs

All 10 comments

Thanks for the issue. I don't have time to work on it. Anyone is welcome.

Also happens when dealing with inkscape svgs

@danilofuchs, when you save the SVG in Inkscape as an "Optimized SVG", you do not get this error.

That's a solution, but I wish svgr just ignored the tags

I think the error is clear enough, namespaces are not supported in React Native.

@neoziro Shouldn't this be fixed in SVGR? It's transforming SVG images to a format that throws an error.

We can't handle it. I think it is not supported by react-native-svg.

But the error is not coming from react-native-svg, but from React.

The same error will be thrown even if you don't use React Native.

Yeah it is because of JSX, it does not support namespace tag. What should we do? SVGO takes care of removing them.

What should we do? SVGO takes care of removing them.

It could be changed to:

<svg xmlns="http://www.w3.org/2000/svg">
  <!-- more tags here -->
</svg>

https://developer.mozilla.org/en-US/docs/Web/SVG/Namespaces_Crash_Course#Declaring_namespaces

The namespace declaration is provided by the xmlns attribute. This attribute says that the tag and its child tags belong to whichever XML dialect has the namespace name 'http://www.w3.org/2000/svg' which is, of course, SVG. Note the namespace declaration only needs to be provided once on a root tag. The declaration defines the default namespace, so the user agent knows that all the tag's descendant tags also belong to the same namespace. User agents check to see if they recognize the namespace name to determine if they know how to handle the markup.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rosenfeld picture rosenfeld  路  6Comments

7ynk3r picture 7ynk3r  路  4Comments

chloesun picture chloesun  路  6Comments

VincentCATILLON picture VincentCATILLON  路  5Comments

kg-currenxie picture kg-currenxie  路  4Comments