-
Notifications
You must be signed in to change notification settings - Fork 29
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
isSvg expects string but gets object (buffer) #62
Comments
I did a pull request to fix it, hope it gets accepted soon |
The changes in the PR appear to solve the issue for me as well. |
Whatsapp!) 👋 What were you expecting to happen?I expected to get the minimized What actually happened?I got 12 errors with main trouble consisting of Please give us a sample of your webpack.config.jsMy entire boilerplates are at: The webpack.config.(js|ts) are at (cwd relative) Terminal output / screenshotsThe full log emited by Webpack 5 v5.91.0 via production mode bundle (development one works smoothly)$ npm run build Please provide the following information:OS & version [e.g. MacOS Catalina 10.15.4]: Windows 10 Pro v1803 (i.e. Windows 10 v10.0.17134) (more details via Steps to reproduce:
npm run html works fine;
npm un imagemin imagemin-svgo
npm i -D imagemin imagemin-svgo
npm run build Additional informationThe exceptions are emitted only via actual |
For what it's worth I don't believe that the PR actually fixed the problem for me. It solved the error message, but it looks like the SVG images were not actually getting optimized anymore. I ended up going a different route and no longer using this package, so I can't help on this issue any further. 🤷 |
Update is braking the filechecker. See: imagemin/imagemin-svgo#62
FWIW The v5 release notes of is-svg state:
|
imagemin-svgo v11.0.0 incorrectly calls isSvg(), breaking the filechecker: See: imagemin/imagemin-svgo#62 Co-authored-by: Claas Augner <[email protected]>
For developers who uses https://github.com/webpack-contrib/image-minimizer-webpack-plugin, we allow directly usage new ImageMinimizerPlugin({
minimizer: [
{
implementation: ImageMinimizerPlugin.imageminMinify,
options: {
// Lossless optimization with custom option
// Feel free to experiment with options for better result for you
plugins: [
["gifsicle", { interlaced: true }],
["jpegtran", { progressive: true }],
["optipng", { optimizationLevel: 5 }],
],
},
},
{
implementation: ImageMinimizerPlugin.svgoMinify,
options: {
encodeOptions: {
// Pass over SVGs multiple times to ensure all optimizations are applied. False by default
multipass: true,
plugins: [
{
name: "preset-default",
params: {
overrides: {
removeViewBox: false,
addAttributesToSVGElement: {
params: {
attributes: [{ xmlns: "http://www.w3.org/2000/svg" }],
},
},
},
},
},
],
},
},
},
],
}); |
Alexander, you ' re great Wizard!)))) 🔮🔮🔮🔮🔮 |
@Dmitriy-Frostoff ⭐ Done |
I'm not using webpack, but I started using svgo and is-svg directly. import imagemin from 'imagemin'
import imageminPng from 'imagemin-pngquant'
import isSVG from 'is-svg'
import { optimize as optimizeSVG } from 'svgo'
// ...
await imagemin(
[
'./public/**/*.{png,svg}',
],
{
plugins: [
async (buffer) => {
const stringData = buffer.toString()
if (isSVG(stringData)) {
const result = optimizeSVG(stringData, { multipass: true })
return Buffer.from(result.data)
}
return buffer
},
imageminPng({
quality: [1, 1]
})
]
}
)
// ... |
There is an issue with the newest release: "imagemin-svgo" hands over a buffer object to "isSvg", which fails because it only works with strings.
The text was updated successfully, but these errors were encountered: