next-optimized-images icon indicating copy to clipboard operation
next-optimized-images copied to clipboard

Detection of optimization libraries incorrect with yarn berry + workspaces

Open osdiab opened this issue 3 years ago • 6 comments

Thanks for the great project!

With v2, I was using it in one nextJS project but then I made a new one where my NextJS project is part of a yarn workspaces monorepo, but when I start it up I get the error that image compression libraries aren't present.

so I moved the imagemin package deps to the root package.json of the yarn workspace, and now next-optimized-images is happy. It seems that next-optimized-images isn't looking at the actually installed packages for the monorepo subpackage, but I haven't looked into the code to see why that is.

osdiab avatar Jan 14 '21 09:01 osdiab

Seems that require.resolve() isn't a reliable way to determine if a package is installed for pnp packages, and that this library uses it for that purpose.

So the trick is probably to use a pnp-compatible package resolver like one referenced in the yarn article above.

osdiab avatar Jan 14 '21 09:01 osdiab

I don't know what are the pros and cons of libraries out there but Webpack has one. https://github.com/webpack/enhanced-resolve

osdiab avatar Jan 14 '21 09:01 osdiab

Perhaps the real move is to just use version 3 though.

osdiab avatar Jan 14 '21 09:01 osdiab

Seems that require.resolve() isn't a reliable way to determine if a package is installed for pnp packages, and that this library uses it for that purpose.

It is perfectly fine to use it for that, but only if you require from a location that declares them, i'm guessing the resolvePath is pointing to the wrong place

merceyz avatar Jan 30 '21 13:01 merceyz

@osdiab how did you solve it? I tried to require imagemin but still getting error.

simPod avatar Dec 04 '22 13:12 simPod

Lol I just gave up on using it with pnp

osdiab avatar Dec 05 '22 03:12 osdiab