From 0f34110ce2218dd1633d487f12d00ba9990c4aee Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 26 Jul 2023 16:11:35 +0200 Subject: [PATCH] fix svgr snippet in nextjs docs --- code/frameworks/nextjs/README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/code/frameworks/nextjs/README.md b/code/frameworks/nextjs/README.md index d15ad4d4a98a..4d9ea8542470 100644 --- a/code/frameworks/nextjs/README.md +++ b/code/frameworks/nextjs/README.md @@ -827,10 +827,15 @@ Below is an example of how to add svgr support to Storybook with this framework. export default { // ... webpackFinal: async (config) => { + config.module = config.module || {}; + config.module.rules = config.module.rules || []; + // This modifies the existing image rule to exclude .svg files // since you want to handle those files with @svgr/webpack - const imageRule = config.module.rules.find((rule) => rule.test.test('.svg')); - imageRule.exclude = /\.svg$/; + const imageRule = config.module.rules.find((rule) => rule?.['test']?.test('.svg')); + if (imageRule) { + imageRule['exclude'] = /\.svg$/; + } // Configure .svg files to be loaded with @svgr/webpack config.module.rules.push({