Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG Transformer Broken #6688

Open
dioptre opened this issue Aug 5, 2021 · 9 comments
Open

SVG Transformer Broken #6688

dioptre opened this issue Aug 5, 2021 · 9 comments

Comments

@dioptre
Copy link

dioptre commented Aug 5, 2021

In the example here:
https://github.com/parcel-bundler/website/blob/v2/src/recipes/react.md

You could also do something like "react-svg:*.svg": ["@parcel/transformer-svg-react"] instead, then only imports with that prefix would be transformed into React Components: import MyIcon from "react-svg:./MyIcon.svg";

I tried this and it didn't work.
Using:

import Logo from 'react-svg:../../img/logo-text.svg';

Results in Error:

Error: No transformers found for frontend/www/src/img/logo-text.jsx with pipeline: 'react-svg'.

  Error: No transformers found for frontend/www/src/img/logo-text.jsx with pipeline: 'react-svg'.
  at ParcelConfig.

.parcelrc

{
  "extends": "@parcel/config-default",
  "transformers": {
    "react-svg:*.svg": ["@parcel/transformer-svg-react"]
  }
}
Software Version(s)
Parcel 2 rc0
Node 14.15
npm/Yarn berry
Operating System mac

Thanks!

@mischnic
Copy link
Member

mischnic commented Aug 5, 2021

I wrote that section of the docs without testing it 😶

Something like this should be possible though, one way or another

@AlexMoutonNoble
Copy link

Hi Folks.
Any motion on this thread?
I notice that using "@parcel/transformer-svg-react" seems to preclude use of url: pipeline for svgs? Am I seeing that right?

Thanks
Alex

@AntonOfTheWoods
Copy link

Does anyone have a workaround they can share?

@mischnic
Copy link
Member

mischnic commented Sep 17, 2021

Don't use a pipeline, this will transform every svg import into a react component:

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.svg": ["@parcel/transformer-svg-react"]
  }
}

@AntonOfTheWoods
Copy link

Don't use a pipeline, this will transform every svg import into a react component:

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.svg": ["@parcel/transformer-svg-react"]
  }
}

Thanks, I did actually stumble across this later but ended up having to manually convert my svgs to tsx with svgr because I couldn't find a way of telling transformer-svg-react not to use svgo, which I have to do because it borks the svgs (actually, not mine but from http://samherbert.net/svg-loaders/). I couldn't find any docs and from the code I couldn't work out how to not use svgo.

@AlexMoutonNoble
Copy link

We have SVGs that are referenced by path/filename in BodyMovin animation files. We cant have these be converted to React components but would like to have them be handled by our bundler.

@dioptre
Copy link
Author

dioptre commented Sep 20, 2021 via email

@reyronald
Copy link

I also cannot use the transformer on all SVGs and need a way to exclude some. Any update on this or does anyone have a workaround?

@TheNathanBlake
Copy link

Don't use a pipeline, this will transform every svg import into a react component:

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.svg": ["@parcel/transformer-svg-react"]
  }
}

I've just tried using this .parcelrc config, while importing to one of my React components:

import Workbench from '../../icons/workbench.svg';

Doing this gives me a "@parcel/transformer-js: cannot access a scoped thread local variable without calling set first" error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants