gilbarbara / react-inlinesvg

An SVG loader component for ReactJS

Home Page:https://codesandbox.io/s/github/gilbarbara/react-inlinesvg/tree/main/demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: src.match is not a function

beqramo opened this issue · comments

commented

Hi, after updating to the react-script 4.0 and to react 17 this error appeared on my screen sadly.

image

Hey @beqramo

The error means the src isn't a string so it doesn't have the match method on its prototype. You need to make sure it is a string...

This most certainly isn't a problem with this package but something that has changed in CRA 4.0 which is a major upgrade...

Did you check CRA changelog? Try to remove your node_modules and reinstall again as suggested.

commented

I did the same way as suggested but I see the same error again, have you tested it with CRA 4.0?

thanks for your answer

I didn't test it with CRA 4, but it doesn't matter.
The error is clear, src isn't a string.

commented

yes, I understand your point but my concern is that everything worked perfectly before updating so this is why I think that it isn't coming from me. if I had a time today I will check it on fresh CRA 4.0 project. thanks

I don't think it's coming from your code but CRA 4.0 it's a major upgrade with breaking changes.

commented

do you have time to have a look at it?

@beqramo
Just tried it with a fresh CRA 4.0 instance and it's working ok.

Are you import the SVG from your project? CRA uses the svgr's webpack loader that converts SVGs to react components, so you probably don't need this package for this case.
Anyway, try to log the src you are passing to it and make sure it's a string. If it a React component, it will never work.

@beqramo The demo is updated with react-scripts 4.0 and everything is working