This is a minimal reproduction case for image compression failures when using @rsbuild/plugin-image-compress with rspack 1.6.x.
After upgrading from rspack 1.5.3 to 1.6.2, image compression fails with:
- JPEG files:
Compress JPEG failed Any { .. } - PNG files:
Optimize failed Invalid header detected; Not a PNG file
@rspack/core: 1.6.2 (fails) vs 1.5.3 (works)@rsbuild/plugin-image-compress: 1.3.1@napi-rs/image: 1.11.2 (transitive dependency)
src/test.jpg- 259KB progressive JPEGsrc/test.png- 681KB PNG
Both images are valid and verified with file command.
cd repro
npm installThis will install both rspack versions using npm aliases:
rspack-core-1.5(rspack 1.5.3)rspack-core-1.6(rspack 1.6.2)
npm run build:1.5Expected: Build succeeds ✅
Actual Result:
Rspack 1.5.3 compiled with 2 warnings in 5.94 s
Build completed!
Images are successfully compressed and output to dist/.
npm run build:1.6Expected: Build fails with image compression errors ❌
Actual Result:
ERROR in × "d37f2fa28b53c09c.jpg" in "/path/to/repro" from Image Minimizer:
│ Compress JPEG failed Any { .. }
ERROR in × "211c9e79656758be.png" in "/path/to/repro" from Image Minimizer:
│ Optimize failed Invalid header detected; Not a PNG file
Rspack 1.6.2 compiled with 2 errors in 42 ms
npm run test:bothThis will run both builds in sequence to demonstrate the difference.
npm run cleanThis reproduction uses npm package aliases to install both rspack versions simultaneously:
rspack-core-1.5: Alias for@rspack/core@1.5.3rspack-core-1.6: Alias for@rspack/core@1.6.2
The build scripts (build-1.5.js and build-1.6.js) are Node.js wrappers that:
- Explicitly require the correct rspack version using the alias
- Load the shared
rspack.config.js - Run the rspack compiler programmatically
- Report build status and errors
This approach ensures that each build uses the exact rspack version being tested.
See rspack.config.js for the minimal configuration using ImageMinimizerPlugin with:
- JPEG compression using
@napi-rs/image - PNG lossless compression using
@napi-rs/image
Expected: Images should be compressed successfully in both rspack versions.
Actual:
- rspack 1.5.3: ✅ Works correctly
- rspack 1.6.2: ❌ Fails with cryptic Rust error messages
- The error messages
Any { .. }suggest Rust error details are being lost in the FFI boundary - The images are valid (verified with
fileandhexdump) - Disabling image compression allows the build to succeed
- The issue affects both JPEG and PNG formats