question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERROR in ../../node_modules/antd-mobile/es/assets/slider-thumb.svg

See original GitHub issue

Version of antd-mobile

5.0.0-beta.16

Operating system and its version

iOS, Android

Browser and its version

Chrome v96.0.4664.45

Sandbox to reproduce

No response

What happened?

svg-sprite-loader@6.0.0

There is some problems when using svg-sprite-loader , if you already using svg in your project, and configure svg-sprite-loader in your webpack, when using some components i.e Slider, an error will throw out through webpack and says “ERROR in …/…/node_modules/antd-mobile/es/assets/slider-thumb.svg”

And I was trying to exclude node_modules in the config file, and then I got an .svg file that need an loader problem

在使用了svg-sprite-loader, 导致一些组件在使用 svg 作为icon的时候报错 "ERROR in ../../node_modules/antd-mobile/es/assets/slider-thumb.svg" , 如果把 node_modules 排出的话,又报 .svg 需要一个 loader 的错误

Relevant log output

ERROR in ../../node_modules/antd-mobile/es/assets/slider-thumb.svg
Module build failed (from ../../node_modules/svg-sprite-loader/lib/loader.js):
ExtractPluginMissingException: svg-sprite-loader exception. svg-sprite-loader in extract mode requires the corresponding plugin
    at Object.loader (D:\Sunglink\OSAP-SSP\node_modules\svg-sprite-loader\lib\loader.js:47:13)
 @ ../../node_modules/css-loader/dist/cjs.js!../../node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[1].use[2]!../../node_modules/antd-mobile/es/components/slider/slider.css 5:0-74 7:73-102


and in webpack config

```js
{
    test: /\.svg$/,
    use: ['svg-sprite-loader'],
},


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
zzzgydicommented, Dec 9, 2021
{
    test: /node_modules\/.+\.svg$/,
    use: {
        loader: 'file-loader',
    },
},
{
    test: /\.svg$/,
    use: {
        loader: 'svg-sprite-loader',
        options: {
            exclude: [/node_modules/],
        },
    },
},

这个配置不生效是因为你是Windows,路径问题,可以将file-loader的test设置成/node_modules[\\/].+\.svg$/。然后就是exclude字段写在options里好像是没有用的,写在外面就有用了。所以可以写成下面这样:

{
  test: /node_modules[\\/].+\.svg$/,
  use: "file-loader",
},
{
  test: /\.svg$/,
  exclude: /node_modules/,
  use: "svg-sprite-loader",
},

或者这样吧

{
  test: /\.svg$/,
  exclude: /node_modules/,
  use: "svg-sprite-loader",
},
{
  test: /\.svg$/,
  include: /node_modules/,
  use: "file-loader",
},
0reactions
xiaohuonicommented, Dec 20, 2021

我有个相似的问题

esbuild 要对 svg 做特殊处理。可以使用 '.svg': 'dataurl',

https://github.com/umijs/umi-next/pull/217

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest cannot load svg file - Stack Overflow
In my app I use React and TypeScript. I tried to run jest tests I get following error:.
Read more >
Troubleshooting SVG image errors in Mapbox Studio | Help
Learn how to fix SVG upload errors in Mapbox Studio. ... The Mapbox Studio style editor supports the SVG format for icons and...
Read more >
Cricut Design Space Unsupported File Type Error ... - YouTube
This video shows the most common reasons for SVG upload errors in Cricut Design Space, such as the unsupported file type error.
Read more >
Crash when handle unsupported SVG and not throw error
I have an issue : sharp is crash when resize then write toFile on specific svg the problem is : toFile is not...
Read more >
Namespaces crash course - SVG: Scalable Vector Graphics
This tells the user agent that the particular parameter belongs to the namespace assigned to the namespace prefix (XLink), and is a parameter ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found