skip to Main Content

I am new to Openshift 3.11 deployment, I created a Multistage Dockerfile for a React application, the build want correctly on my local machine, but when I run on the openshift cluster I get the error below:

> [email protected] 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

and this is my 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

3

Answers


  1. Vite by default uses an html page as an entry point. So you either need to create one or if you don’t have an html page you can use it in "Library Mode".

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

    From the docs:

    // 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'
            }
          }
        }
      }
    })
    
    Login or Signup to reply.
  2. If you’re using ES Modules (i.e., import sytax):

    Look in your package.json to confirm type field is set to module:

    // vite.config.js
    import * as path from 'path';
    import { defineConfig } from "vite";
    
    const config = 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'
            }
          }
        }
      }
    })
    
    export default config;
    
    Login or Signup to reply.
  3. Had same issue because of .dockerignore. Make sure your index.html not ignored.
    In case if you ignoring everything (**) you can add !index.html to the next line and try.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search