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

SVGR doesn`t support Windows with turbopack on Next.js 15 #985

Open
1MPULSEONE opened this issue Dec 24, 2024 · 0 comments
Open

SVGR doesn`t support Windows with turbopack on Next.js 15 #985

1MPULSEONE opened this issue Dec 24, 2024 · 0 comments

Comments

@1MPULSEONE
Copy link

1MPULSEONE commented Dec 24, 2024

🐛 Bug Report

When connecting svgr to my new project on Next.js 15, I encountered my page crashing with the following error:

Error: Switched to client rendering because the server rendering errored:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

At the same time, my partner runs the application on Linux without any problems. Everything works fine on Versel as well.

To Reproduce

Example.tsx

import IconDelete from '~/shared/assets/icons/icondeleteblack.svg';

const Example: React.FC = () => {
  return (
    <div>
      <IconDelete/>
    </div>
  )
}

next.config.js

/**
 * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
 * for Docker builds.
 */
/** @type {import("next").NextConfig} */
const config = {
    webpack(config) {
        // Grab the existing rule that handles SVG imports
        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
    },
};

export default config;

Problem solving

What worked for me to solve the problem was to simply turn off the turbo pack

Before:

  "scripts": {
    "dev": "next dev --turbo",
  },

After:

  "scripts": {
    "dev": "next dev",
  },
@1MPULSEONE 1MPULSEONE changed the title SVGR doesn`t support Windows with turbopack SVGR doesn`t support Windows with turbopack on Next.js 15 Dec 24, 2024
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

1 participant