-
Notifications
You must be signed in to change notification settings - Fork 937
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
Only default export (as string) is available for SVG files runtime after bit start is executed #4462
Comments
Something similar when I import font or svg by css inside my react component. |
any news here? |
I will check. Why not import the svg as a regular react component? // CurvePeek.tsx:
export function CurvePeek() {
return (
<svg
viewBox="0 0 100 100"
preserveAspectRatio="none"
className="curvePeek"
>
<path d="M 0,100 Q 50,-100 100,100" />
</svg>
);
} |
looking into it, it seems to be a problem with Webpack 5 compatibility: We seem to had supported it using a babel plugin, like so:
The way I see it, there are two easy options:
{
test: /\.svg$/,
type: 'asset',
}
{
test: /\.svg$/,
use: ['@svgr/webpack']
] Combining the two generates an inline url from the react component, which accomplishes nothing. I'm trying to use |
I made #4595. I tested it and it works locally. |
Hi, |
@dimo-ivanov - maybe the CRA has a different config for svgr? |
I'm having this issue too, Icons work on bit.dev but not in CRA. How was this resolved? |
I am having the same issue as @dimo-ivanov |
This example component failed for me with the same error. |
You can resolve this by adding a webpack config in your CRA app for loading svg files. Bit's UI uses @svgr/webpack, but there are numerous loaders available depending on your requirements. The same is true for any application build, for instance nextJs requires adding config to get this working too. This isn't a bit issue, so I'm not sure what else we can help with I'm afraid |
I had a similar issue - moving a component library from an integrated package, bundled with Rollup. I found it confusing that icons worked well locally and on bit.cloud but not when consumed in a Create React App. That was until I realized icons had previously been compiled with svgr/rollup. As I wanted the icons to be consumable by any React application I decided to have them precompiled and generated with svgr-cli before exporting them to bit.cloud. I experienced these problems with CRA4. CRA5 should be able to render svgr as it stands. Hope this helps. |
svgr is non standard and needs to be included in your bundler :) This is why I'm not keen on adding non canonical things to bit. |
Hi there!, {
test: /\.(svg)$/,
use: ['@svgr/webpack', 'file-loader']
} check this out for your reference, petatemarvin26/vin-react |
Hi All, |
Describe the bug
Using
@svgr/webpack
should provide an alternative export of an SVG file as a ReactComponent.Afrer executing
bit start
there is an error/warningSteps to Reproduce
Exporting an SVG as a ReactComponent option is declared by `react-scripts' like this
react-app-env.d.ts
file/// <reference types="react-scripts" />
to make the ReactComponent from SVG available.
and use it in the component as a component
bit start
Expected Behavior
Imported SVG file should be available as a ReactComponent runtime (after executing
bit start
)Specifications
for harmony workspace
The text was updated successfully, but these errors were encountered: