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.

importing .svg does not work on the web, Warning: </static/media/splashScreen.0f923900.svg /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.

See original GitHub issue

I have installed in my project expo install react-native-svg.

I have exported the svg as a component by doing:

import Logo from './logo.svg';
export default Logo;

It can render on native but fail on the web.

bundle.js:69367 Warning: </static/media/splashScreen.0f923900.svg /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.

I have followed that configuration https://github.com/react-native-community/react-native-svg#use-with-svg-files

My metro.config.js is equal:

const { getDefaultConfig } = require('metro-config');

module.exports = (async () => {
  const {
    resolver: { sourceExts, assetExts },
  } = await getDefaultConfig();
  return {
    transformer: {
      babelTransformerPath: require.resolve('react-native-svg-transformer'),
    },
    resolver: {
      assetExts: assetExts.filter(ext => ext !== 'svg'),
      sourceExts: [...sourceExts, 'svg'],
    },
  };
})();

My app.json got added

{
+    "packagerOpts": {
+      "config": "metro.config.js",
+      "sourceExts": ["js", "jsx", "ts", "tsx", "svg"]
+    },
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
porscommented, Feb 24, 2021

The fact that you get a uri instead of a react component means that you already have configured how to handle .svg files. You should just use that uri with a export default () => <img href={uri} />

For anyone going this path (like I did), make sure to use src instead of href.

2reactions
msandcommented, Jan 3, 2020

I’m not using any .svg files in any expo web project at the moment. So I have no such example to show you as I haven’t even attempted to do what you’re doing. Expo has a default metro / webpack configuration, but it’s not my expertise, and completely unrelated to this library.

you can use: File.js File.web.js File.ios.js File.android.js File.windows.js File.native.js File.future.platform.js File.custom.test.e2e.js File.jest.js

and do this in e.g. ExtraFile.js:

import File from './File'
export default () => <File with="extra stuff" />

and it’ll use the platform specific one depending on what you’ve made available and how you’ve configured metro / webpack / rollup / other web bundlers you’ve chosen to use.

Read more comments on GitHub >

github_iconTop Results From Across the Web

import SVG as React Components with webpack 5
Use PascalCase for React components, or lowercase for HTML elements. and the SVG doesn't show. I can't import it as a React Component....
Read more >
How to use SVGs in React | Sanity.io guide
There are a few ways to use an SVG in a React app: Use it as a regular image; Import it as a...
Read more >
How to use SVG Icons as React Components - Robin Wieruch
A walkthrough on how to use SVG Icons in React applications. SVGR + Webpack are the perfect fit to make it happen...
Read more >
How To Import SVGs into NextJS | Frontend Digest
Then we can import our SVG file as normal, and use it like any other React component. 2. Use babel-plugin-react-svg. If you prefer...
Read more >
How to Import SVGs in a React and Vite app - freeCodeCamp
Are you having difficulties importing SVGs into your React app? This is a problem that many developers face, especially when setting up a ......
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