N
Nuxt2mo ago
Devin

IPX_ERROR when using nuxt/image in dockerfile

Ive created this dockerfile to build my nuxt project like the following:
FROM oven/bun:latest as build

WORKDIR /app
COPY package.json bun.lockb tsconfig.json ./

RUN bun install --verbose

# Copy the rest of the application files
COPY . .

# Build the application for production
RUN bun run build

RUN rm -rf .output/server/node_modules
RUN bun install --cwd .output/server/

FROM node:lts-slim as runner

ENV NODE_ENV=PRODUCTION
EXPOSE 3000

WORKDIR /app

COPY --from=build /app/.output .output

ENTRYPOINT ["node", ".output/server/index.mjs"]
FROM oven/bun:latest as build

WORKDIR /app
COPY package.json bun.lockb tsconfig.json ./

RUN bun install --verbose

# Copy the rest of the application files
COPY . .

# Build the application for production
RUN bun run build

RUN rm -rf .output/server/node_modules
RUN bun install --cwd .output/server/

FROM node:lts-slim as runner

ENV NODE_ENV=PRODUCTION
EXPOSE 3000

WORKDIR /app

COPY --from=build /app/.output .output

ENTRYPOINT ["node", ".output/server/index.mjs"]
Without
RUN rm -rf .output/server/node_modules
RUN bun install --cwd .output/server/
RUN rm -rf .output/server/node_modules
RUN bun install --cwd .output/server/
The resulting image is "broken" because i get the IPX_ERROR from nuxt/image when loading my images. Does somebody have an idea, without this workaround?
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @Devin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The issue you're experiencing with the IPX_ERROR from nuxt/image when building your Nuxt project in a Docker container is a known problem, especially when deploying to different environments. Let's address this based on the information provided in the knowledge sources. The error you're encountering is likely related to the Sharp package, which is used by nuxt/image for image processing. This error often occurs when the pre-built binaries for Sharp are not compatible with the target environment. Here are a few potential solutions and considerations: 1. Install Sharp for the target platform: As mentioned in the Stack Overflow post about nuxt/image in production (https://stackoverflow.com/questions/77745608), you might need to rebuild Sharp for the target platform. You can try adding this command to your Dockerfile after the installation step:
RUN npm rebuild --arch=x64 --platform=linux --libc=musl sharp

RUN npm rebuild --arch=x64 --platform=linux --libc=musl sharp

This rebuilds Sharp for the Linux environment you're deploying to. 2. Use a multi-stage build: Your current Dockerfile is already using a multi-stage build, which is good practice. However, you might want to ensure that you're copying all necessary files from the build stage to the runner stage. Make sure you're not missing any required dependencies or files. 3. Configure Nuxt Image: In your nuxt.config.ts file, you might need to specify the directory where your images are located. As mentioned in the Stack Overflow post about NuxtImage returning 404 (https://stackoverflow.com/questions/77730500), add this configuration:
export default defineNuxtConfig({
image: {
dir: 'assets/img'
},
})

export default defineNuxtConfig({
image: {
dir: 'assets/img'
},
})

Adjust the dir value according to where your images are actually stored. 4. Check for environment-specific issues: As noted in the Nuxt Image troubleshooting guide (https://image.nuxt.com/get-started/installation#troubleshooting), if you're still encountering issues, it might be related to your OS architecture or NodeJS version. Ensure you're using an LTS version of Node.js and that your target environment (in the Docker container) matches the requirements for Sharp and nuxt/image. 5. Consider using a different base image: Instead of node:lts-slim, you might want to try a more complete base image like node:lts or node:lts-alpine which might include necessary dependencies for Sharp. If none of these solutions work, you might need to investigate further. The Nuxt Image documentation on static images (https://image.nuxt.com/advanced/static-images) suggests that for static sites, you might need to pre-render your images. However, this doesn't seem to be directly applicable to your server-side rendering setup. Remember, the workaround you're currently using (removing and reinstalling node_modules in the output directory) is addressing a symptom rather than the root cause. It would be better to solve the underlying issue with Sharp and the nuxt/image module compatibility in your Docker environment. If you continue to face issues after trying these solutions, you may need to open an issue on the Nuxt Image GitHub repository (https://github.com/nuxt/image/issues) with detailed information about your setup, error traces, and the steps you've tried. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@276016956245540864> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Devin
DevinOP2mo ago
My guess is its the bun building env, so i will try around with fixing that
Want results from more Discord servers?
Add your server