Closed bewards closed 1 year ago
Closing as I found the following configurations works for me after restarting the docker service where my application was running in:
/**
* @param {import('next').NextConfig} nextConfig
*/
const svgrPlugin = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack: (config, options) => {
// Grab the existing rule that handles SVG imports
const fileLoaderRule = config.module.rules.find((rule) => rule.test?.test?.('.svg'));
config.module.rules.push(
// Convert all other *.svg imports to React components
{
test: /\.svg$/,
issuer: /\.[jt]sx?$/,
resourceQuery: /react/,
use: ['@svgr/webpack'],
}
);
// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i;
fileLoaderRule.test = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp)$/i;
console.log(config.module.rules);
// Overload the Webpack config if it was already overloaded
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options);
}
return config;
},
});
};
module.exports = svgrPlugin;
i cant fix it :(
🐛 Bug Report
When I use SVGR with webpack, I get Object instead of React Components.
To Reproduce, use this config:
and import like this:
Error Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Expected behavior I expect to get a React component.
package.json
End User Screenshot of Error
Webpack dump webpack.config.dump.txt