-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[turbopack] SVG via svgr support #4832
Comments
To chime in, I'm getting similar issues with SVGR after upgrading to 13.4.1 too I'm importing SVGs in from a
Errors after importing/using in the Next 13.4 app router app (not in pages). Unsure whether this is a Next issue, or Turborepo one |
We don't currently support SVGR loader natively, though it could probably be enabled using module.exports = {
experimental: {
turbo: {
loaders: {
'.svg': ['@svgr/webpack'],
},
},
},
}; Also @pkolt, the {
"compilerOptions": {
"paths": {
"public/*": ["./public/*"]
}
}
} |
Hi @jridgewell ! I tried to do what you described, but unfortunately it did not help me. I get an error: There is a https://github.com/pkolt/pkolt.ru/blob/master/public/images/calendar.svg?short_path=e465239#L0-L1 Thanks! |
I have the same issue, is there any fix available for this? |
Found a related issue here vercel/next.js#48140 It was caused by turbopack trying to get the dimension of svg but webpack already turn the import into a function |
The whole world needs to know about this. I just fixed hours and hours of frustration by adopting this simple little change. |
Idk anything about how Turbopack nor Rust works but it seems
Hoping that SVG support becomes built in or more formally supported without hacks like the above! |
This issue seemed to be resolved in the latest with-turbopack-loaders example with Works for me in my project, however with this config, the usage of |
Thanks @tntchn. It worked for me on both configs, just for changing a fill color 🥳
|
This has completely resolved the issue, thank you! |
Thanks, it works with Next.js v14 as well. Wondering when it finally transitions from experimental to stable :) |
This is working as expected with |
Using it like that for the last few days, didn't see issues so far. But it was not so easy to find, so I'd close it after documenting properly. Wondering when can it go out of "experimental" though. |
Worked for me too, can be closed. |
You saved my life thanks brother ! |
How can I configure it if I want to keep the original module.exports = {
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: 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
},
// ...other config
} |
Which version of framework you are using ? |
I'm using Nextjs 14.2.3 |
I've configured this hope this helps you If you are using turbo repo
and this is the svgr config
for typescript support use this
How I use those file: file:
usage
:) |
If I understood right from the turbo docs page, the There's the with-turbopack-loaders example in the repo that covers this usecase and currently works with latest Next.js. This all being said, I've wasted a few hours on this and just can't get it working with Next 14 and Typescript 5, always getting back As a workaround, I'm just converting the SVGs to React components with https://react-svgr.com/playground/ now |
Like @Yihao-G I still have problem with loading And this is my webpack configuration: webpack(config) {
const defaultSvgLoader = config.module.rules.find((rule) => rule.test?.test?.('.svg'))
config.module.rules.push(
{
...defaultSvgLoader,
test: /\.svg$/i,
resourceQuery: {not: [...defaultSvgLoader.resourceQuery.not, /react/]}, // exclude if *.svg?react
},
{
test: /\.svg$/i,
issuer: defaultSvgLoader.issuer, // issuer: /\.[jt]sx?$/ doesn't work:
// https://github.com/vercel/next.js/issues/48177#issuecomment-1506251112
resourceQuery: /react/, // *.svg?react
use: '@svgr/webpack',
},
)
return config
} As you can see, I can use How can I configure the similar behaviour for Turbopack? |
@mirismaili Turbopack doesn't support resourceQuery. We can import SVG as React component without passing "?react". If we want to use SVG image as |
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> Currently, if you are using Next.js 15 have SVGR enabled via `WithNx` and are using turbopack. You could potentially have issues loading your svg. This happens because of how webpack imports svg and not having an additional configuration for turbopack (currently it is under the experimental option). ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Moving forward, we can call this out and deprecate the option to be removed in Nx 21. As such should you need to use SVGs it is recommended to do so manually. Something similar to [this comment](vercel/turborepo#4832 (comment)). ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> Currently, if you are using Next.js 15 have SVGR enabled via `WithNx` and are using turbopack. You could potentially have issues loading your svg. This happens because of how webpack imports svg and not having an additional configuration for turbopack (currently it is under the experimental option). ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Moving forward, we can call this out and deprecate the option to be removed in Nx 21. As such should you need to use SVGs it is recommended to do so manually. Something similar to [this comment](vercel/turborepo#4832 (comment)). ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
What version of Turborepo are you using?
next@13.4.1
What package manager are you using / does the bug impact?
npm
What operating system are you using?
Mac
Describe the Bug
In Next.js, I use the SVG image include using the svgr webpack plugin.
Next.js config:
Unfortunately when using
next dev --turbo
I get errors:Expected Behavior
SVG pictures are loaded by picking up settings from
next.config.js
or by turbopack mechanisms.To Reproduce
Open repository
Reproduction Repo
https://github.com/pkolt/pkolt.ru
The text was updated successfully, but these errors were encountered: