Using Docker causes Unhandled Runtime Errors!

Hello,
I have a project that uses React and Laravel. The compose file and Dockerfile for the React project are as follows:

services:

  # React Frontend
  portal-view:
    container_name: portal-view
    build:
      context: /home/Projects/portal-view/
      dockerfile: Dockerfile
    environment:
      - NODE_ENV=development
      - CHOKIDAR_USEPOLLING="true"
      - WATCHPACK_POLLING="true"
      - NEXT_TELEMETRY_DISABLED=1
      - MAX_OLD_SPACE_SIZE=4096
      - GENERATE_SOURCEMAP=false # Reduces build size
      - INLINE_RUNTIME_CHUNK=false
      - USER_ID=${USER_ID:-999}
      - GROUP_ID=${GROUP_ID:-995}
    user: "${USER_ID:-999}:${GROUP_ID:-995}"
    volumes:
      - /home/Projects/portal-view:/app
      - /app/node_modules          
      - /app/.next
    ports:
      - "127.0.0.1:3000:3000"               
    deploy:
      resources:
        limits:
          cpus: '4.0'
          memory: 4G

And:

FROM node:24-alpine

# Create non-root user with configurable UID/GID
ARG USER_ID=999
ARG GROUP_ID=995

RUN addgroup -g ${GROUP_ID} appuser && \
    adduser -S -u ${USER_ID} -G appuser appuser

WORKDIR /app

COPY package*.json ./

# Install dependencies as root first
RUN npm install -g npm@latest && \
    npm install --legacy-peer-deps

# Create .next directory with correct permissions
RUN mkdir -p /app/.next && \
    chown -R ${USER_ID}:${GROUP_ID} /app/.next

COPY --chown=${USER_ID}:${GROUP_ID} . .

# Ensure proper permissions for node_modules
RUN chown -R ${USER_ID}:${GROUP_ID} /app/node_modules

USER ${USER_ID}

EXPOSE 3000

CMD ["npm", "run", "dev"]

When I open website pages, I see the following error:

This error is 100% related to your Docker because the website works without Docker. Does anyone have experience fixing such a problem?

I think instead of having a large number of images, Docker should be consistent so that these strange problems don’t arise.

Thank you.