Sharp Missing after PKG
Unanswered
Orangetailed potter wasp posted this in #help-forum
Orangetailed potter waspOP
{
"name": "client",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"pkg": "pkg . --out-path dist --targets node18-win-x64"
},
"bin": "server.js",
"pkg": {
"scripts": [
".next/**/*.js",
"node_modules/**/*",
"node_modules/sharp/**/*"
],
"assets": [
".next/**/*",
"node_modules/**/*",
"public/**/*",
"node_modules/sharp/**/*",
".env"
],
"targets": [
"node18-win-x64"
]
},
"dependencies": {
"@headlessui/react": "^2.1.2",
"@heroicons/react": "^2.1.5",
"axios": "^1.7.3",
"cors": "^2.8.5",
"next": "14.2.5",
"next-auth": "^4.24.7",
"pkg": "^5.8.1",
"radix-ui": "^1.0.1",
"react": "^18",
"react-dom": "^18",
"sharp": "^0.33.5"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"esbuild": "0.23.1",
"eslint": "^8",
"eslint-config-next": "14.2.5",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}My app works fine when I start it with
node server.js but when I build it i get the missing Sharp error. // next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
env: {
API_URL: process.env.API_URL,
},
output: "standalone",
};
export default nextConfig;Docker image:
FROM node:18-alpine AS base
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi
FROM base AS executable
WORKDIR /app
ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN chown -R nextjs:nodejs /app
COPY --from=builder /app/public ./public
RUN mkdir .next
RUN chown nextjs:nodejs .next
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
RUN npm install -g pkg
USER nextjs
# IDK why but this is needed in order to work with pkg
RUN sed -i 's/process.chdir(__dirname)//g' server.js
RUN npm run pkg
FROM alpine:latest as final
WORKDIR /output
COPY --from=executable /app/dist/client.exe /output/client.exe
ENTRYPOINT ["/output/client.exe"]6 Replies
Orangetailed potter waspOP
Unsing "sharp": "0.32.6" did not work :((
.\client.exe 14:05:02
▲ Next.js 14.2.5
- Local: http://localhost:3000
- Network: http://0.0.0.0:3000
✓ Starting...
✓ Ready in 105ms
⨯ Error: 'sharp' is required to be installed in standalone mode for the image optimization to function correctly. Read more at: https://nextjs.org/docs/messages/sharp-missing-in-production
⨯ Error: 'sharp' is required to be installed in standalone mode for the image optimization to function correctly. Read more at: https://nextjs.org/docs/messages/sharp-missing-in-production@Orangetailed potter wasp Unsing "sharp": "0.32.6" did not work :((
Manx
Hi did you already find the solution? i'm facing the same issue as well
Orangetailed potter waspOP
Nah. I just ignore the error for now
If I find a solution i will write down here
@Orangetailed potter wasp If I find a solution i will write down here
Manx
Thank you so muchhh