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.

Can't import svgs

See original GitHub issue

If I want to import my svg like import Star from '../../assets/svgs/pinnedStar.svg'; I get this error

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: number.

my rn-cli.config.js:

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

module.exports = mergeConfig(
  async () => {
    const {
      resolver: { sourceExts, assetExts },
    } = await getDefaultConfig();
    console.log(sourceExts);

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:27 (16 by maintainers)

github_iconTop GitHub Comments

4reactions
Sankalp-Saxenacommented, May 28, 2020

@kristerkari svg image is opening on devices but not on web getting following error,

DOMException: Failed to execute ‘createElement’ on ‘Document’: The tag name provided (‘/static/media/events-qengage.89418f90.svg’) is not a valid name.

2reactions
kristerkaricommented, May 12, 2019

@danbockapps and for typescript you might need to do declare module "*.svg";, I’m not sure, but you can try that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to import svg files in typescript - Stack Overflow
If you use webpack, you can do this by creating a custom types file. Create a file named custom.d.ts with the following content:...
Read more >
Bug: [5.0] SVGs cannot be imported (not as components, but ...
Describe the bug When importing a SVG in a regular manner (not as a component): import Logo from './logo.svg' There is an error...
Read more >
What if You Can't Import a File? | SVGator Help
What if you can't import a file · 1. If it's not a static SVG file · 2. If the code includes unrecognizable...
Read more >
Importing svg not working properly - Ask the community
Note that if that SVGs are exported from Illustrator, masks in them won't import to Figma correctly. Also defs and use are not...
Read more >
How to Import SVGs in a React and Vite app - freeCodeCamp
In this article, I will share with you the different ways of importing SVGs in React, as well as how the process works...
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