Why next throw error when i import .svg icons with 'svgr' in server component?
Unanswered
Somali posted this in #help-forum
SomaliOP
i got error about 'you need use specific loader to load this file' until i write 'use client'
7 Replies
Boreal Chickadee
I'm having the same issue!
Boreal Chickadee
@Somali did you manage to make it work?
@Boreal Chickadee <@236135464078278656> did you manage to make it work?
SomaliOP
i just put 'use client'
Normally, Next.js has built-in support for importing .svg images via its own image loader
The following code works in the latest version of Next.js (13.4.19)
Don't sure if it's what you're looking for
SVGR seems can't work great with Next.js in server components for now, You may use this as an alternative
Also, have you checked your webpack configuration?
It's working in my side project which is using Next.js App Router
The following code works in the latest version of Next.js (13.4.19)
import DollarSvg from './dollarcircle.svg'
...
return <Image width={50} height={50} alt="fds" src={DollarSvg} />Don't sure if it's what you're looking for
SVGR seems can't work great with Next.js in server components for now, You may use this as an alternative
Also, have you checked your webpack configuration?
/** @type {import('next').NextConfig} */
const config = {
reactStrictMode: true,
webpack: config => {
config.module.rules.push({
test: /\.svg$/i,
use: ['@svgr/webpack']
})
return config
}
}It's working in my side project which is using Next.js App Router
Boreal Chickadee
yep I did, nothing worked so eventually I implemented the first option
@fuma Normally, Next.js has built-in support for importing .svg images via its own image loader
The following code works in the latest version of Next.js (13.4.19)
ts
import DollarSvg from './dollarcircle.svg'
...
return <Image width={50} height={50} alt="fds" src={DollarSvg} />
Don't sure if it's what you're looking for
SVGR seems can't work great with Next.js in server components for now, You may use this as an alternative
Also, have you checked your webpack configuration?
js
/** @type {import('next').NextConfig} */
const config = {
reactStrictMode: true,
webpack: config => {
config.module.rules.push({
test: /\.svg$/i,
use: ['@svgr/webpack']
})
return config
}
}
It's working in my side project which is using Next.js App Router
SomaliOP
yes that work with Image comp, but i need inline svg to change colors, i also have same config so this is not working
Surprisingly, I have tried in the latest version and it worked
You can try it in CodeSandbox: https://codesandbox.io/p/sandbox/laughing-liskov-7df7j6
You can try it in CodeSandbox: https://codesandbox.io/p/sandbox/laughing-liskov-7df7j6