nuxt / image

Plug-and-play image optimization for Nuxt applications.
https://image.nuxt.com
MIT License
1.34k stars 272 forks source link

`sharp` optional binaries not included in `.output` #1257

Open Aareksio opened 8 months ago

Aareksio commented 8 months ago

Reproduction

git clone git@github.com:nuxt/image.git
cd image
pnpm install
pnpm dev:prepare
pnpm build
pnpm dev:build
rm -rf node_modules/@img
node playground/.output/server/index.mjs

Open: http://localhost:3000/provider/ipx


[500] [IPX_ERROR] Could not load the "sharp" module using the ... runtime

Sharp binaries, bundled as @img/sharp-*, are not included in generated .output. Tests may pass, because of module resolution. We need to isolate .output (or delete root project node_modules, as with reproduction), as it should be done in production.

Related: https://github.com/lovell/sharp/issues/4000 (cross architecture build) Related: #1237, #1210 (either cross architecture build or isolating .output) Related: #1253 (both cross architecture build and isolating .output)


Workaround before this gets fixed: downgrade sharp to 0.32.6 via your package manager.

tasiotas commented 8 months ago

I couldn't get it working with pnpm and supportedArchitectures. Had to go back to Yarn... 😟

alimozdemir commented 8 months ago

This is a blocker for me right now, either I will remove nuxt-image or I will find a workaround with pnpm. It is very annoying

juane1000 commented 7 months ago

The latest update (1.4.0) shoots my server build to 50MB+ from ~12-ishh. Is this intentional/desirable? Seem exorbitant. I was unaware that the the plugin included resizing functionality. Is there an option to exclude the "sharp" dependency from the server bundle and have it installed in the deployment server environment? Thanks.

DamianGlowala commented 6 months ago

Has anyone found a workaround with pnpm? This is also a blocker for me at the moment.

UPDATE: added sharp 0.33.3 (or higher) to overrides and it works correctly.

oripka commented 6 months ago

Has anyone found a workaround with pnpm? This is also a blocker for me at the moment.

UPDATE: added sharp 0.33.3 to overrides and it works correctly.

This is the only fix that worked for me, everything else described even using the latest nuxt image version failed when deploying a nuxt project built on m1 to a linux x64 server.

oripka commented 3 months ago

I just moved to a monorepo setup and had to include nuxt-image and the override in the root package.json in order to make this work. First I had nuxt-image as a dependency in the base layer and no matter where I applied overrides it would not work.

{
    "devDependencies": {
        "@nuxt/image": "^1.7.0"
    },
    "pnpm": {
        "overrides": {
            "sharp": "0.33.4"
        },
        "supportedArchitectures": {
            "os": [
                "current",
                "linux"
            ],
            "cpu": [
                "x64",
                "arm64"
            ]
        }
    },
    "packageManager": "pnpm@9.6.0+sha512.38dc6fba8dba35b39340b9700112c2fe1e12f10b17134715a4aa98ccf7bb035e76fd981cf0bb384dfa98f8d6af5481c2bef2f4266a24bfa20c34eb7147ce0b5e"
}