【问题标题】:Vite: Could not resolve entry module (index.html)Vite:无法解析入口模块(index.html)
【发布时间】:2022-06-14 05:34:36
【问题描述】:

我是 Openshift 3.11 部署的新手,我为 React 应用程序创建了一个 Multistage Dockerfile,构建希望在我的本地机器上正确,但是当我在 openshift 集群上运行时,我收到以下错误:

> kncare-ui@0.1.0 build
> tsc && vite build

vite v2.9.9 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 (/app/node_modules/rollup/dist/shared/rollup.js:198:30)
    at ModuleLoader.loadEntryModule (/app/node_modules/rollup/dist/shared/rollup.js:22680:20)
    at async Promise.all (index 0)
error: build error: running 'npm run build' failed with exit code 1

这是我的Dockefile

FROM node:16.14.2-alpine as build-stage      
RUN mkdir -p /app/
WORKDIR /app/
RUN chmod -R 777 /app/
COPY package*.json /app/
COPY tsconfig.json /app/
COPY tsconfig.node.json /app/
RUN npm ci
COPY ./ /app/
RUN npm run build

FROM nginxinc/nginx-unprivileged 
#FROM bitnami/nginx:latest
COPY --from=build-stage /app/dist/ /usr/share/nginx/html
#CMD ["nginx", "-g", "daemon off;"]
ENTRYPOINT ["nginx", "-g", "daemon off;"]
EXPOSE 80

【问题讨论】:

    标签: node.js docker dockerfile openshift


    【解决方案1】:

    Vite 默认使用 html 页面作为入口点。因此,您要么需要创建一个,要么如果您没有 html 页面,您可以在“库模式”中使用它。

    https://vitejs.dev/guide/build.html#library-mode

    来自文档:

    // vite.config.js
    const path = require('path')
    const { defineConfig } = require('vite')
    
    module.exports = defineConfig({
      build: {
        lib: {
          entry: path.resolve(__dirname, 'lib/main.js'),
          name: 'MyLib',
          fileName: (format) => `my-lib.${format}.js`
        },
        rollupOptions: {
          // make sure to externalize deps that shouldn't be bundled
          // into your library
          external: ['vue'],
          output: {
            // Provide global variables to use in the UMD build
            // for externalized deps
            globals: {
              vue: 'Vue'
            }
          }
        }
      }
    })
    

    【讨论】:

      猜你喜欢
      • 2022-09-23
      • 1970-01-01
      • 2019-07-27
      • 2017-12-28
      • 2017-12-11
      • 2018-11-10
      • 2020-04-15
      • 2021-07-14
      • 2021-11-07
      相关资源
      最近更新 更多