Next.js 14 (app router) import SVG – Unsupported Server Component type: {…}

If you encountered the error:

Error: Unsupported Server Component type: {...}

when attempting to add an SVG import file in your component in following way

import LogoSvg from "@/assets/icons/logo.svg";

export interface FooterProps {}

export function Footer() {
  return (
    <footer>
      <LogoSvg />
    </footer>
  );
}

then Next.js is indicating that you’re trying to import a file (as a React component) that is not supported.

To quickly resolve this error, you need to add appropriate loading rules to your next.config.js file:

const nextConfig = {
 webpack(config) {
    // Grab the existing rule that handles SVG imports
    // @ts-ignore - rules is a private property that is not typed
    const fileLoaderRule = config.module.rules.find(rule =>
      rule.test?.test?.('.svg'),
    );

    config.module.rules.push(
      // Reapply the existing rule, but only for svg imports ending in ?url
      {
        ...fileLoaderRule,
        test: /\.svg$/i,
        resourceQuery: /url/, // *.svg?url
      },
      // Convert all other *.svg imports to React components
      {
        test: /\.svg$/i,
        issuer: fileLoaderRule.issuer,
        resourceQuery: { not: [...fileLoaderRule.resourceQuery.not, /url/] }, // exclude if *.svg?url
        use: ['@svgr/webpack'],
      },
    );
    // Modify the file loader rule to ignore *.svg, since we have it handled now.
    fileLoaderRule.exclude = /\.svg$/i;

    return config;
  }
}

and install

npm i @svgr/webpack --save-dev

This solution I found on stackoverflow and works perfectly for Next ^13 running on “app router”.

Hope it helps !