-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[Bug]: After upgrade to v8.1.1 svg loader doesn't work for nextjs #27195
Comments
@valentinpalkovic I don't think we should be patching PRs like #27093 back to |
I will do some investigations on Tuesday, but on the first look I can’t see any relation to the mentioned PR. @SalOne22 Is the issue reproducible on 8.1.0? |
No issue on 8.1.0, all works as expected |
Ok. So, I figured out what the issue is. Indeed, #27093 causes the issue for you because you don't mutate every loader, which matches {
imageRule: {
resourceQuery: /raw/,
type: 'asset/source',
++ test: /^(?!__barrel_optimize__)/
}
} Therefore, this rule will be your first finding. Indeed, we have several loaders that would process 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"),
- );
- if (imageRule) {
- imageRule["exclude"] = /\.svg$/;
- }
+ config.module.rules.forEach((rule) => {
+ if (rule?.["test"]?.test(".svg")) {
+ rule!["exclude"] = /\.svg$/;
+ }
+
+ return rule;
+ });
// Configure .svg files to be loaded with @svgr/webpack
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"],
});
return config;
}, I hope this helps. @shilman It doesn't matter whether we would have released this in 8.2 or 8.1.1. This was a custom |
@valentinpalkovic It absolutely matters. If it's in the prerelease the community has up to two months to test it before it goes out. We've d found plenty of corner cases this way in the past. |
Okay, it works now. Thanks for the fast reply! The documentation should be updated to include this change so new users will not get confused by this: https://storybook.js.org/docs/get-started/nextjs#custom-webpack-config. |
Excellent point! @SalOne22 I just got one thing in mind: One downside of my approach is that as soon as Something like this: 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"),
- );
- if (imageRule) {
- imageRule["exclude"] = /\.svg$/;
- }
+ config.module.rules.forEach((rule) => {
+ if (rule?.["test"]?.test(".svg") && rule?.issuer?.not?.test(".css")) {
+ rule!["exclude"] = /\.svg$/;
+ }
+
+ return rule;
+ });
// Configure .svg files to be loaded with @svgr/webpack
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"],
});
return config;
}, @jonniebigodes, Can you take care of the documentation? Please ping me if you want to adjust the documentation. I would say we have to document it differently for pure Webpack5 and Next.js projects. |
@valentinpalkovic appreciate you tagging me on this. I'll take a look at this next week and follow up with you when the pull request is up. Sounds like a plan? |
Describe the bug
After I upgraded storybook version from v8.0.10 to v8.1.1 my custom svgr loader broke. I have setup based on official storybooks nextjs documentation:
But I keeping receiving this error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Reproduction link
https://codesandbox.io/p/devbox/storybook-next-svgr-pzn4gm?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clwcn9n4l0007356gxvhpe2n3%2522%252C%2522sizes%2522%253A%255B51.77874186550976%252C48.22125813449024%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clwcn9n4k0002356gnsfntpmf%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clwcn9n4k0004356gb4zj1d30%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clwcn9n4k0006356gfq8gaoju%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clwcn9n4k0002356gnsfntpmf%2522%253A%257B%2522id%2522%253A%2522clwcn9n4k0002356gnsfntpmf%2522%252C%2522activeTabId%2522%253A%2522clwcng7oe00a8356grmipax1h%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clwcn9n4k0001356gicqnqtxc%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%257D%252C%257B%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252Fnextjs%252Fdefault-ts%252Fnext.config.mjs%2522%252C%2522id%2522%253A%2522clwcng7oe00a8356grmipax1h%2522%252C%2522mode%2522%253A%2522temporary%2522%257D%255D%257D%252C%2522clwcn9n4k0006356gfq8gaoju%2522%253A%257B%2522id%2522%253A%2522clwcn9n4k0006356gfq8gaoju%2522%252C%2522tabs%2522%253A%255B%255D%257D%252C%2522clwcn9n4k0004356gb4zj1d30%2522%253A%257B%2522id%2522%253A%2522clwcn9n4k0004356gb4zj1d30%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clwcnagkn003i356gmbbd59fe%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522clwcnaifj003odbfm7tt5abe6%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clwcnagkn003i356gmbbd59fe%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D
Reproduction steps
System
Additional context
This may be caused by:
Next.js: Avoid conflicts with the raw loader - #27093
The text was updated successfully, but these errors were encountered: