-
Notifications
You must be signed in to change notification settings - Fork 27k
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
squoosh crash on static import png #26527
Comments
It does not affect all PNG files it seems. Had to many different bugs last few days, currently no time debugging another one (this one comes just after another one fixed with the static import of images and right into the next bug ;( ) |
Might be this: GoogleChromeLabs/squoosh#1057 |
I'm also seeing this in Ubuntu in WSL as we upgrade to Next 11.0.1 -- even images that don't throw an error in the build process are showing up with encoding errors in the browser. As a workaround it looks like you can disable static images in
and use Webpack asset modules instead, e.g.
|
Thanks to @velvetkevorkian 's solution, while using TypeScript I have to use additional loaders to conform the new typings defined for images. const assetRegex = new RegExp(`.(png|jpe?g|gif|woff|woff2|ico|svg)$`);
config.module.rules.push({
test: assetRegex,
use: [
{
loader: 'string-replace-loader',
options: {
search: 'export default (.*)',
replace: (_, src) =>
`export default { src: ${src.replace(/;$/, '')} }`,
flags: 'm',
},
},
{
loader: 'url-loader',
options: { outputPath: './static/assets/' },
},
],
type: 'javascript/auto',
}); import img from 'path/to/image.png';
<img src={img.src} /> |
I think it may have to do with the image ratio. Both jpg and png images below make the build crash. When using the jpg image, the error is:
When using the png image, the error is:
|
@dperetti AFAIK it adds an option to use an alternative transformer. Because I'v looked through canary pre-release change-logs and so far did not see fix for this in general. Obviously this option is nice for those who are blocked by this issue! Regarding this issue: If it is related to the previously linked issue, nextjs team could fix this generally, by bumping squoosh version used. |
Bump `squoosh` to the latest version, currently commit [cad09160](GoogleChromeLabs/squoosh@cad0916). Ideally, we would use the version published to npm but it hasn't been published in [two months](https://www.npmjs.com/package/@squoosh/lib?activeTab=versions) and we have a patch (#23565) that isn't available upstream. This also is a precursor to getting support for AVIF. - Fixes #27092 - Fixes #26527 - Reapplies the patch from #23565
This has been fixed in v11.1.3-canary.46. You can try it out today with |
Just a heads up, I don't think bumping squoosh solved the issue, at least on macOS. Here's a minimal test case with If you |
FYI this seems to be broken on |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bump `squoosh` to the latest version, currently commit [cad09160](GoogleChromeLabs/squoosh@cad0916). Ideally, we would use the version published to npm but it hasn't been published in [two months](https://www.npmjs.com/package/@squoosh/lib?activeTab=versions) and we have a patch (vercel#23565) that isn't available upstream. This also is a precursor to getting support for AVIF. - Fixes vercel#27092 - Fixes vercel#26527 - Reapplies the patch from vercel#23565
What version of Next.js are you using?
11.0.1
What version of Node.js are you using?
14.15.0
What browser are you using?
firefox
What operating system are you using?
linux
How are you deploying your application?
other
Describe the Bug
static import of png:
$ grep unwrap_throw -r node_modules
binary file: node_modules/next/dist/next-server/server/lib/squoosh/png/squoosh_png_bg.wasm
binary file: node_modules/next/dist/next-server/server/lib/squoosh/png/squoosh_oxipng_bg.wasm
Expected Behavior
no error
To Reproduce
statically import a png file and use the import in jsx/tsx code
The text was updated successfully, but these errors were encountered: