0

I recently migrate a small exercice project from CRA to Vite, and it use Docker, however since Vite is installed as Dev dependency, and i am running npm run install --omit=dev so it may explain why I am getting this error :

> #12 0.726 > npm run build --prefix client
> #12 0.726
> #12 1.193
> #12 1.193 > project@2.0.0 build
> #12 1.193 > vite build --emptyOutDir
> #12 1.193
> #12 1.199 sh: vite: not found

So is there a way to only install Vite and omit all the rest dependency which is not needed on the production, or I have to install normally with all the packages with npm run install by default ? The Docker file is as follow :

 FROM node:lts-alpine

WORKDIR /app

COPY package*.json ./

COPY client/package*.json client/
RUN npm run install-client --omit=dev

COPY server/package*.json server/
RUN npm run install-server --omit=dev

COPY client/ client/
RUN  npm run build

COPY server/ server/

USER node

CMD [ "npm", "start", "--prefix", "server" ]

EXPOSE 8000
ShueiYang
  • 648
  • 1
  • 3
  • 7

1 Answers1

1

You may try to install vite globally and use multi-stage builds to be able exclude vite dependencies from node_modules folder:

FROM node:lts-alpine as builder

WORKDIR /app
# vite will be installed in npm global directory
RUN npm install -g vite
COPY package*.json ./
COPY client/package*.json client/
RUN npm run install-client --omit=dev
COPY server/package*.json server/
RUN npm run install-server --omit=dev
COPY client/ client/
RUN  npm run build
COPY server/ server/

FROM node:lts-alpine
# copy built files from builder image to new clean node image without vite
COPY --from=builder /app /app
WORKDIR /app

USER node

CMD [ "npm", "start", "--prefix", "server" ]

EXPOSE 8000
rzlvmp
  • 7,512
  • 5
  • 16
  • 45
  • thanks for the reply ^^, well i get a different error now saying : `failed to load config from /app/client/vite.config.js` `Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'vite' imported from /app/client/vite.config.js..` – ShueiYang Apr 30 '23 at 17:32
  • Well I found a workaround but your multi-stage solution is really interesting and is useful I will look it again – ShueiYang Apr 30 '23 at 22:42