vue3 and vite.js, docker build production failed "Error: Could not resolve entry module (index.html)."

vue3 and vite.js, docker build production failed "Error: Could not resolve entry module (index.html)."

我正在尝试使用 vite.js 构建一个 vue3 项目。我想在 Dockerfile 中构建它,但出现以下错误。

vite v2.9.5 building for production...
✓ 0 modules transformed.
Could not resolve entry module (index.html).
error during build:
Error: Could not resolve entry module (index.html).
    at error (/panda-planner/frontend-planner/node_modules/rollup/dist/shared/rollup.js:198:30)
    at ModuleLoader.loadEntryModule (/panda-planner/frontend-planner/node_modules/rollup/dist/shared/rollup.js:22480:20)
    at async Promise.all (index 0)
Error response from daemon: The command '/bin/sh -c npm run build' returned a non-zero code: 1
Failed to deploy '<unknown> Dockerfile: Dockerfile': Can't retrieve image ID from build stream

我一直在寻找有关汇总的信息,但我不明白它是什么。我的命令 npm run build 在我的电脑上也能完美运行。

有人可以帮我吗?

我的vite.config.js

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import eslintPlugin from "vite-plugin-eslint";

const path = require("path");

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), eslintPlugin()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
});

我的 Dockerfile

# Build backend application
FROM node:14.19.1-alpine AS builder
WORKDIR /panda-planner/backend-planner/
COPY /backend-planner/package*.json .
RUN npm install
COPY . .
RUN npm run build
EXPOSE 1337
CMD ["npm", "run", "start" ]

# Build frontend application
FROM builder as frontend
WORKDIR /panda-planner/frontend-planner/
COPY /frontend-planner/package*.json .
RUN npm install --legacy-peer-deps
COPY . .
RUN npm run build

# Setup nginx server for frontend
FROM nginx:stable-alpine as nginx
COPY --from=frontend /frontend-planner/dist /usr/share/nginx/html
#COPY ./default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;" ]

我的错-_-!

前端COPY路径出错

此解决方案有效:

# Build backend application
FROM node:14.19.1-alpine AS builder
WORKDIR /panda-planner/backend-planner/
COPY /backend-planner/package*.json .
RUN npm install
COPY /backend-planner/ .
RUN npm run build
EXPOSE 1337
CMD ["npm", "run", "start" ]

# Build frontend application
FROM builder AS frontend
WORKDIR /panda-planner/frontend-planner/
COPY /frontend-planner/package*.json .
RUN npm install --legacy-peer-deps
COPY /frontend-planner/ .
RUN npm run build

# Setup nginx server for frontend
FROM nginx:stable-alpine AS nginx
COPY --from=frontend /panda-planner/frontend-planner/dist/ /usr/share/nginx/html/
#COPY ./default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;" ]