For production Image Optimization with Next.js, the optional 'sharp' package is strongly recommended

bsandruHOBBY

a year ago

Hello,

I added 'sharp' in the dependency pack, but I still receive the following message:
For production Image Optimization with Next.js, the optional 'sharp' package is strongly recommended. Run 'npm i sharp', and Next.js will use it automatically for Image Optimization.
Read more: https://nextjs.org/docs/messages/sharp-missing-in-production

Please let me know how I could fix this?
Thanks!

Solved

3 Replies

a year ago

Do you use npm, yarn, or pnpm?

Do you have only one of their lockfiles?

Do you have sharp installed via your package manager of choice?

Is gcc-unwrapped being installed during build?


bsandruHOBBY

a year ago

I use yarn on railway and npm locally. I have the yarn.lock and package-lock.json
I installed sharp using 'npm i sharp'
I use Next.js Image component.

Don't know if gcc-unwrapped is installed or not….

[Region: us-west1]

==============

Using Nixpacks

context: 834a5780e46fc4241ac4b6eb34dc6a04

╔══════════════ Nixpacks v1.21.2 ═════════════╗

║ setup │ nodejs18, yarn-1x ║

║─────────────────────────────────────────────║

║ install │ yarn install --frozen-lockfile ║

║─────────────────────────────────────────────║

║ build │ yarn run build ║

║─────────────────────────────────────────────║

║ start │ yarn run start ║

╚═════════════════════════════════════════════╝

0 building with "default" instance using docker driver

1 [internal] load build definition from Dockerfile

1 transferring dockerfile: 3.33kB done

1 DONE 0.1s

2 [internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1707782610

2 DONE 0.4s

3 [stage-0 1/15] FROM ghcr.io/railwayapp/nixpacks:ubuntu-1707782610@sha256:8f4b0fd95dc3311cf9a59f236d8d7d7f956fe21a2a1d64b53c82f12c4e859f09

3 DONE 0.0s

4 [internal] load .dockerignore

4 transferring context: 2B done

4 DONE 0.0s

5 [internal] load build context

5 transferring context: 8.31MB 0.1s done

5 DONE 0.1s

6 [stage-0 2/15] WORKDIR /app/

6 CACHED

7 [stage-0 3/10] COPY .nixpacks/nixpkgs-bf744fe90419885eefced41b3e5ae442d732712d.nix .nixpacks/nixpkgs-bf744fe90419885eefced41b3e5ae442d732712d.nix

7 CACHED

8 [stage-0 4/10] RUN nix-env -if .nixpacks/nixpkgs-bf744fe90419885eefced41b3e5ae442d732712d.nix && nix-collect-garbage -d

8 CACHED

9 [stage-0 5/10] COPY . /app/.

9 DONE 0.2s

10 [stage-0 6/10] RUN --mount=type=cache,id=s/dc576b8f-59b6-44ee-a1a9-e7c25b4c8fe0-/usr/local/share/cache/yarn/v6,target=/usr/local/share/.cache/yarn/v6 yarn install --frozen-lockfile

10 0.752 yarn install v1.22.22

10 0.837 warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.

10 0.841 [1/4] Resolving packages…

10 1.923 [2/4] Fetching packages…

10 2.444 [3/4] Linking dependencies…

10 2.449 warning "@mantine/next > @mantine/ssr@6.0.21" has unmet peer dependency "@emotion/server@>=11.4.0".

10 2.471 warning Workspaces can only be enabled in private projects.


a year ago

I use yarn on railway and npm locally

Mixing package managers is never a good idea, please pick one and stick with it.


Status changed to Solved railway[bot] about 1 year ago