24 days ago
error: Could not load the "sharp" module using the linux-x64 runtime
Possible solutions:
- Ensure optional dependencies can be installed:
npm install --include=optional sharp
- Ensure your package manager supports multi-platform installation:
See https://sharp.pixelplumbing.com/install#cross-platform
- Add platform-specific dependencies:
npm install --os=linux --cpu=x64 sharp
- Consult the installation documentation:
See https://sharp.pixelplumbing.com/install
My Dockerfile:
FROM oven/bun:latest
WORKDIR /app
COPY . .
# Clean up any existing node_modules and lock files to ensure a fresh install
RUN rm -rf node_modules
RUN rm bun.lock
# Install dependencies and build the server
RUN bun install
RUN bun build --compile --target bun --outfile server src/index.ts
# Expose the port that the server will run on
EXPOSE 80
# Start the server
CMD ["./server"]---
Already tried the possible solutions but no changes
Pinned Solution
24 days ago
Hello dariowskii,
i think the issue isn't sharp's installation it's your bun build --compile step. bun's compiler cannot embed native .node addons like sharp into the binary so at runtime it looks for node_modules which isn't there anymore
drop the compile step entirely and just run your typescript directly with bun. change your dockerfile cmd to:
cmd ["bun", "run", "src/index.ts"]
and remove these two lines:
run bun build --compile --target bun --outfile server src/index.ts
cmd ["./server"]
keep node_modules in the container that's it
Hope this help you :)
2 Replies
Status changed to Open Railway • 24 days ago
24 days ago
Hello dariowskii,
i think the issue isn't sharp's installation it's your bun build --compile step. bun's compiler cannot embed native .node addons like sharp into the binary so at runtime it looks for node_modules which isn't there anymore
drop the compile step entirely and just run your typescript directly with bun. change your dockerfile cmd to:
cmd ["bun", "run", "src/index.ts"]
and remove these two lines:
run bun build --compile --target bun --outfile server src/index.ts
cmd ["./server"]
keep node_modules in the container that's it
Hope this help you :)
Status changed to Solved brody • 24 days ago
