Skip to content

@svgr/webpack v6.1 - fails due to a duplicate default export #645

@ghost

Description

🐛 Bug Report

Build fails with svgr/webpack & url-loader due to:

ERROR in ../../libs/ui/src/lib/components/Toggle/on.svg 40:7
Module parse failed: Duplicate export 'default' (40:7)
File was processed with these loaders:
 * ../../node_modules/@svgr/webpack/dist/index.js
 * ../../node_modules/file-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
| export { ForwardRef as ReactComponent };
| export default __webpack_public_path__ + "assets/svg/on.3827650.svg";
> export default __webpack_public_path__ + "assets/svg/on.3827650.svg";

To Reproduce

Steps to reproduce the behavior:

  • Install @svgr/[email protected]
  • Setup webpack similarly to the config below
  • Export an SVG as follows:
export { ReactComponent as StarIcon } from './star.svg'
export { default as StarIcon } from './star.svg'
  • Consume them in the app you're building

Webpack loaders:

{
   module: {
     rules: {
        test: /\.svg$/i,
        oneOf: [
          {
            issuer: /\.[jt]sx?$/,
            use: [
              {
                loader: '@svgr/webpack',
                options: svgrConfig
              },
              {
                loader: 'file-loader',
                options: {
                  limit: 10000, // 10kB
                  name: '[name].[hash:7].[ext]',
                  outputPath: 'assets/svg'
                }
              }
            ]
          },
          {
            type: 'asset/resource',
            generator: {
              filename: 'assets/svg/[name].[hash][ext][query]'
            }
          }
        ]
     }
   }
}

Expected behavior

Should not error, just as previous versions - works as expected on 6.0.0

Link to repl or repo (highly encouraged)

Please provide a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

Run npx envinfo --system --binaries --npmPackages @svgr/core,@svgr/cli,@svgr/webpack,@svgr/rollup --markdown --clipboard

Paste the results here:

## System:
 - OS: macOS 12.0.1
 - CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
 - Memory: 2.36 GB / 32.00 GB
 - Shell: 5.8 - /bin/zsh
## Binaries:
 - Node: 16.13.0 - /usr/local/bin/node
 - Yarn: 3.1.0 - /usr/local/bin/yarn
 - npm: 8.1.0 - /usr/local/bin/npm
## npmPackages:
 - @svgr/rollup: 5.5.0 => 5.5.0 
 - @svgr/webpack: 6.1.0 => 6.1.0 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions