How to deploy unplugin-icons on production?

For a SolidStart project, I'm using this library https://github.com/antfu/unplugin-icons as Icon Components. I follow the instructions in the page and have it working on local perfectly. However as I deploy to production, using Docker, I got this error
#13 0.788 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'unplugin-icons' imported from /usr/src/app/vite.config.js.timestamp-1688028342588-49d2ca85f27bd.mjs
#13 0.788 at new NodeError (node:internal/errors:399:5)
#13 0.788 at packageResolve (node:internal/modules/esm/resolve:889:9)
#13 0.788 at moduleResolve (node:internal/modules/esm/resolve:938:20)
#13 0.788 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'unplugin-icons' imported from /usr/src/app/vite.config.js.timestamp-1688028342588-49d2ca85f27bd.mjs
#13 0.788 at new NodeError (node:internal/errors:399:5)
#13 0.788 at packageResolve (node:internal/modules/esm/resolve:889:9)
#13 0.788 at moduleResolve (node:internal/modules/esm/resolve:938:20)
The Docker file is
FROM node:18.14.2-alpine

#... omit some credential details
WORKDIR /usr/src/app

# Install all dependencies needed for production build
ENV NODE_ENV production
COPY package.json yarn.lock ./
RUN yarn install \
--prefer-offline \
--frozen-lockfile

# Copy source files
COPY . .

# Build the app
RUN yarn build

# Run the app
CMD [ "yarn", "start" ]
FROM node:18.14.2-alpine

#... omit some credential details
WORKDIR /usr/src/app

# Install all dependencies needed for production build
ENV NODE_ENV production
COPY package.json yarn.lock ./
RUN yarn install \
--prefer-offline \
--frozen-lockfile

# Copy source files
COPY . .

# Build the app
RUN yarn build

# Run the app
CMD [ "yarn", "start" ]
This is due to the fact that unplugin-icons is declared in package.json as devDependency (as told by the library), so when it is installed in PRODUCTION mode, it cannot find the module. Has anyone got it working on production? What is the proper way to use this library?
GitHub
GitHub - antfu/unplugin-icons: 🤹 Access thousands of icons as compo...
🤹 Access thousands of icons as components on-demand universally. - GitHub - antfu/unplugin-icons: 🤹 Access thousands of icons as components on-demand universally.
1 Reply
anhvu0911
anhvu0911OP2y ago
I tried with the dockerfile in https://stackoverflow.com/questions/74222441/how-to-yarn-build-on-dockerfile, where it yarn build as dev first, then remove the node_modules and reinstall as production. It is successfully deployed to the server (I'm using Gitlab CI/CD), but still got the same error on server.
Stack Overflow
How to yarn build on Dockerfile
I try to build a Docker image executing the code: docker build . -t <YOUR_DOCKER_HUB_USERNAME>/my-nuxt-project It is about a nuxt.js project but when I run the code I receive the following er...
Want results from more Discord servers?
Add your server