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

Unable to Import svg as React Component #421

Open
FoonkG opened this issue Jan 12, 2021 · 7 comments
Open

Unable to Import svg as React Component #421

FoonkG opened this issue Jan 12, 2021 · 7 comments

Comments

@FoonkG
Copy link

FoonkG commented Jan 12, 2021

  • electron-builder Version: 22.9.1
  • electron-webpack Version: 2.8.2
  • Target: Windows, Mac

I'm trying to import a SVG as a React Component.

import { ReactComponent as Icon} from "../assets/icon.svg";

When i try to do this, i get errors like this.
image

I've tried using svgr without any luck.

webpack.main.additions.js

module.exports = (config) => {
	return {
		...config,
		devtool: false,
		module: {
			rules: [
				{
					test: /\.ts$/,
					loader: "ts-loader",
				},
				{
					test: /\.html$/,
					use: "html-loader",
				},
				{
					test: /\.svg$/,
					use: ["@svgr/webpack"],
				},
			],
		},
	};
};
@veighthedev
Copy link
Contributor

Facing the same issue

@loopmode
Copy link
Collaborator

loopmode commented Jan 12, 2021

import { ReactComponent is a preconfigured feature of create-react-app, more specifically of the react-scripts package used by CRA.
electron-webpack has no knowledge of that.

There are many different ways of using svg in react with webpack, you should investigate some more.

@FoonkG
Copy link
Author

FoonkG commented Jan 12, 2021

import { ReactComponent is a preconfigured feature of create-react-app, more specifically of the react-scripts package used by CRA.
electron-webpack has no knowledge of that.

There are many different ways of using svg in react with webpack, you should investigate some more.

I did, most ways are importing SVG then making an <img> and setting that svg as its source but i want it to be an actual svg so i can style it with css etc..

@loopmode
Copy link
Collaborator

Ah. I see. Apologies for being all brainy-smurfy.

@veighthedev
Copy link
Contributor

veighthedev commented Jan 16, 2021

Fix: #422

@marwan-9
Copy link

marwan-9 commented Dec 24, 2023

@FoonkG
make this edit in webpack.config and it will work
use: ["@svgr/webpack", "url-loader'],

@FoonkG
Copy link
Author

FoonkG commented Dec 24, 2023

@FoonkG
make this edit in webpack.config and it will work
use: ["@svgr/webpack", "url-loader'],

Just in time!

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

No branches or pull requests

4 participants