-
-
Notifications
You must be signed in to change notification settings - Fork 421
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
How to modify next.config.js in next 13.3.0? #860
Comments
If someone has the solution it would be nice to update the documentation. |
I'm also facing the kinda same problem for the |
This may be related, about the But for me I managed to make it work with a different issuer (the same So, what I have is: /** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
typedRoutes: true,
},
webpack(config) {
// Grab the existing rule that handles SVG imports
const fileLoaderRule = config.module.rules.find((rule) =>
rule.test?.test?.('.svg')
)
config.module.rules.push(
// Reapply the existing rule, but only for svg imports ending in ?url
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/, // *.svg?url
},
// Convert all other *.svg imports to React components
{
test: /\.svg$/i,
issuer: {not: /\.(css|scss|sass)$/},
resourceQuery: {not: /url/}, // exclude if *.svg?url
loader: '@svgr/webpack',
options: {
dimensions: false,
titleProp: true,
},
}
)
// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i
return config
},
}
module.exports = nextConfig Pass your own options to taste, but note |
Using @jmagrippis's issuer: Before that, I was getting this compilation error: Oddly this error only showed up on a sub-page ( |
i solve it like this
|
Here's how I solved it: webpack(config) {
// Configures webpack to handle SVG files with SVGR. SVGR optimizes and transforms SVG files
// into React components. See https://react-svgr.com/docs/next/
// Grab the existing rule that handles SVG imports
// @ts-ignore - this is a private property that is not typed
const fileLoaderRule = config.module.rules.find((rule) => rule.test?.test?.('.svg'));
config.module.rules.push(
// Reapply the existing rule, but only for svg imports ending in ?url
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/, // *.svg?url
},
// Convert all other *.svg imports to React components
{
test: /\.svg$/i,
issuer: fileLoaderRule.issuer,
resourceQuery: { not: [...fileLoaderRule.resourceQuery.not, /url/] }, // exclude if *.svg?url
use: ['@svgr/webpack'],
}
);
// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i;
return config;
}, |
Thanks @IGassmann, would be great if this was listed in the Docs as a change in config for v13 |
Fixed next.config.js example to a working version per this: #860 (comment) Co-authored-by: Jari Mustonen <jari@itsellesi.fi>
How can I add options in here? |
You can pass custom options by replacing Here's an example of a configuration that configs SVGO to not remove the |
Error still in Next.js 14.2.4
|
After install nextjs I have next.config.js:
In svgo docs another format of next.config.js:
As I understand, I need rewrite config in docs in new format. Could you help with that?
The text was updated successfully, but these errors were encountered: