free(): invalid size
Hi,
Even after upgrading to 2.2.17, I'm still having this issue. Any idea?
Thanks a lot
Astro v4.5.9 AstroCompress v2.2.17
Probably a duplicate of #316
@bngmnn This should've been fixed in v2.2.17
@JeremyJames Can you share some of the images you're trying to compress ? I would like to debug.
@bngmnn This should've been fixed in v2.2.17
@JeremyJames Can you share some of the images you're trying to compress ? I would like to debug.
You are right, the problem is with a specific image. If I remove it, it works well in v2.2.17.
Here's the culprit:
Thanks for helping!
We found the culprit in https://github.com/lovell/sharp/issues/3935#issuecomment-1881866341. Cache will be disabled in v2.2.18
@JeremyJames Should be fixed in v2.2.19
Hello! I'm still getting the error.
I did the following steps:
- Remove
node_modules,.astroanddistfolders - Run
npm install, astro compress v 2.2.19 got installed - Run
npm build:boom: free(): invalid size
Thanks for the help
I've recently noticed this as well with v2.2.17 and v2.2.19: namely in astro dev mode, when an astro image component (eg Astro Picture) is part of the page content.
It looks like the "_image" image endpoint request causes the free(): invalid size crash.
astro build works fine.
I second @jurajkapsz. I first tried removing all images. Then I tried commenting out the only <Picture /> element I have. And then I didn't get any errors β but no pictures π
Can you share a bit of code on how you're running the <Image /> component and <Picture /> component maybe ? I'm trying all sorts of combinations but I can't get it to error. Maybe just an example and a few pictures will do.
compress({
Exclude: [(File: string) => File.indexOf("_image") !== -1],
});
And also does this ππ» help ?
compress({
Exclude: [
(File: string) => {
console.log(File);
return false;
},
],
});
And what is the output of ππ»β?
I've recently noticed this as well with
v2.2.17andv2.2.19: namely inastro devmode, when anastro image component(eg Astro Picture) is part of the page content. It looks like the"_image"image endpoint request causes thefree(): invalid sizecrash.
astro buildworks fine.
This is confirmed in my case. I got the same issue
We don't compress in dev. CompressAstro hooks into the astro:build:done hook and only runs on build.
We don't compress in dev. CompressAstro hooks into the astro:build:done hook and only runs on build.
Right, that's the interesting point, why it happens when CompressAstro is integrated. I'll make the tests you mentioned earlier.
In the meantime I've conditioned its integration in my astro config like so (probably not the proper way, but it works):
integrations: [
import.meta.env.PROD &&
(await import("astro-compress")).default({
CSS: true,
HTML: true,
Image: true,
JavaScript: true,
SVG: true,
}),
],
So, there's a PR available https://github.com/withastro/astro/pull/10616 in favor of disabling the sharp libvips image cache. Maybe it helps. I hope it gets merged and this gets resolved soon.
Can you try the latest astro-compress v2.2.21 and @playform/compress-astro v0.0.2 ? @JeremyJames @jurajkapsz @kristianfrost @enricogallesio
Can you try the latest astro-compress v2.2.21 and @playform/compress-astro v0.0.2
v2.2.21 didn't change anything. What is compress-astro v0.0.2?
I get this error now:
npx astro add @playform/compress-astro
@playform/compress-astro doesn't appear to be an integration or an adapter. Find our official integrations at https://astro.build/integrations
@jurajkapsz it's a deprecated package. In the future only @playform/compress-astro will remain or the new package @playform/compress. They're all the same in terms of functionality just have different names. See: https://github.com/Playform/CompressAstro/issues/324
@kristianfrost I see, it seems that the integration must have an astro-integration keyword in its package.json to be registered as an integration successfully by the Astro component. I removed it from the latest @playform/compress-astro v0.0.2 and astro-compress v2.2.21 as I didn't want to polute this page with https://astro.build/integrations/ two integrations that basically do the same thing internally.
You can add it to your package.json manually and it will still work. Just add:
"dependencies": {
"@playform/compress-astro": "0.0.2"
},
to your package.json and import compress() from @playform/compress-astro.
See: https://github.com/Playform/CompressAstro#install-dependencies-manually
Thank you for the tip! It will be re-added to the latest version.
In reply to this comment:
compress({ Exclude: [(File: string) => File.indexOf("_image") !== -1], });And also does this ππ» help ?
No, it does not. Actually, to get the error, it seems, it is enough to just import the package into the astro config (I have import compress from "astro-compress";) without integrating anything.
In my package.json:
"dependencies": {
"astro-compress": "^2.2.21",
}
compress({ Exclude: [ (File: string) => { console.log(File); return false; }, ], });And what is the output of ππ»β?
Nothing, I get the usual:
free(): invalid size
Aborted (core dumped)
For me, this works fine (ie it does nothing on dev and compresses on build).
@jurajkapsz Hm, interesting..
It seems that importing two sharp instances causes this.
@jurajkapsz @enricogallesio @JeremyJames @bngmnn astro v4.5.15 just got released https://github.com/withastro/astro/blob/refs/heads/main/packages/astro/CHANGELOG.md#4515 with the PR merged - https://github.com/withastro/astro/pull/10616.
Can you give that a try with the latest astro-compress v2.2.21 or @playform/compress-astro v0.0.2 ?
No change after latest updates, the issue remains.
Ok, there's one last resort I would like to try which might have been the culprit all this time https://github.com/Playform/Compress/blob/Current/Source/Function/Integration.ts#L203. Limiting / unlimiting the amount of memory used. I'll release a new version today with unlimited false see if that helps.
No change after latest updates, the issue remains.
Same here, still having the same error
I used the astro-compress 2.2.21 and astro 4.5.15 on cloudflare, no luck. The error is different but may be same rootcause?
10:01:44.414 | munmap_chunk(): invalid pointer
Seems the astro-compress depends on sharp 0.33.3 and astro depends on sharp ^0.32.6, but the actual sharp installed into node_modules is 0.32.6.
As a workaround, overriding sharp version works. tested on cloudflare, the build passed.
"overrides": {
"sharp": "0.33.3"
},
astro-compress v2.2.22 and @playform/compress v0.0.3 have been released with better error checking and unlimited sharp set to false in Source/Function/Integration.ts. Can you give that a try ? @JeremyJames @jurajkapsz @enricogallesio @kristianfrost
I used the
astro-compress 2.2.21andastro 4.5.15on cloudflare, no luck. The error is different but may be same rootcause?10:01:44.414 | munmap_chunk(): invalid pointerSeems the
astro-compressdepends onsharp 0.33.3andastrodepends onsharp ^0.32.6, but the actualsharpinstalled intonode_modulesis0.32.6.As a workaround, overriding
sharpversion works. tested on cloudflare, the build passed."overrides": { "sharp": "0.33.3" },
This will be fixed by https://github.com/Playform/Compress/issues/329. You can track that issue there @c3qo.
astro-compress v2.2.22 and @playform/compress v0.0.3 have been released with better error checking and unlimited sharp set to false in Source/Function/Integration.ts. Can you give that a try ?
Hi @NikolaRHristov , I switched to @playform/compress v0.0.3, and no change.
NB, there is a new warning showing up: