this error occurs when launching storybook, all svg that i use in the application cause an error in ./src/shared/assets/icons/about-20-20.svg ...etc Module build failed (from ./node_modules/@svgr/webpack/dist/index.js):
if i remove all references to svg from the application, then all components in the storybook work correctly
webpack.config.ts storybook webpack config
import webpack, { DefinePlugin, RuleSetRule } from 'webpack';
import path from 'path';
import { buildCssLoader } from '../build/loaders/buildCssLoader';
import { BuildPaths } from '../build/types/config';
export default ({ config }: {config: webpack.Configuration}) => {
const paths: BuildPaths = {
build: '',
html: '',
entry: '',
src: path.resolve(__dirname, '..', '..', 'src'),
};
config.resolve.modules.push(paths.src);
config.resolve.extensions.push('.ts', '.tsx');
// eslint-disable-next-line no-param-reassign
config.module.rules = config.module.rules.map((rule: RuleSetRule) => {
if (/svg/.test(rule.test as string)) {
return { ...rule, exclude: /\.svg$/i };
}
return rule;
});
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
config.module.rules.push(buildCssLoader(true));
config.plugins.push(new DefinePlugin({
__IS_DEV__: true,
}));
return config;
};
main.ts storybook config
import type { StorybookConfig } from "@storybook/react-webpack5";
const config: StorybookConfig = {
stories: [
'../../src/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [
"@storybook/addon-webpack5-compiler-swc",
"@storybook/addon-onboarding",
"@storybook/addon-links",
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/react-webpack5",
options: {
builder: {
useSWC: true
}
},
},
docs: {
autodocs: "tag",
},
swc: () => ({
jsc: {
transform: {
react: {
runtime: 'automatic',
},
},
},
}),
};
export default config;