Encountering difficulties while attempting to deploy image on kubernetes due to issues with packaging structure

After successfully building with the dockerfile provided below, I encountered an issue when trying to deploy my application on EKS.

FROM node:12
# Create app directory
WORKDIR /usr/src/app

COPY udagram-feed/package*.json ./
RUN npm ci 
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "run", "prod" ]

Upon checking the cluster logs, I received the following error message:

internal/modules/cjs/loader.js:960
  throw err;
  ^
Error: Cannot find module '/usr/src/app/www/server.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
    at Function.Module._load (internal/modules/cjs/loader.js:840:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] prod: `tsc && node ./www/server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-05-20T19_11_45_220Z-debug.log

When testing the image locally, the file structure is as follows:

  • Dockerfile
  • node_modules
  • package.json
  • package-lock.json
  • src

The src/ directory contains the serves.ts sequelize.ts and other files. It is apparent that there is no www/ directory. Why is Kubernetes looking for files in this directory? Any assistance would be greatly appreciated. I have been struggling with this issue for days now and am unsure of what steps to take next. For the file structure, please refer to the GitHub repository GitHub

Answer №1

Initially, the Dockerfile you used resulted in a bulky 1GB image. After some modifications, I was able to condense it into a more efficient 240MB image. There is still room for further optimization; you can check out examples of multi-stage Dockerfile creation here and here.

FROM node:12-alpine 
# Set up the app directory
WORKDIR /usr/src/app
# Install necessary app dependencies
# Utilize a wildcard to copy both package.json and package-lock.json
# This ensures compatibility (npm@5+)
COPY package*.json ./
RUN apk add --no-cache --virtual .gyp \
        python \
        make \
        g++ \
    && npm ci \
    && apk del .gyp
# Copy the app source code
COPY . .
EXPOSE 8080
CMD [ "npm", "run", "prod" ]

Take a look at the sizes of the Docker images:

REPOSITORY                          TAG                 IMAGE ID            CREATED             SIZE
udagram-feed-alpine                 latest              185478b5eabc        11 seconds ago      247MB
udagram-feed                        latest              fbf32e67d4fa        4 minutes ago       1.07GB

Furthermore, I noticed that your package.json file is referencing the ./www/server.js file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unleashing the potential of an endless animation by incorporating pauses between each iteration

I am trying to create an infinite animation using animate css but I want to add a delay between each iteration. After exploring various options, I first attempted to achieve this using plain JavaScript. Here is the HTML snippet: <div id="item" class= ...

How can I showcase array elements using checkboxes in an Ionic framework?

Having a simple issue where I am fetching data from firebase into an array list and need to display it with checkboxes. Can you assist me in this? The 'tasks' array fetched from firebase is available, just looking to show it within checkboxes. Th ...

Error message "Cannot find children property on type IntrinsicAttributes & RefAttributes<unknown>" occurring in a React component due to a Typescript issue

Issue: The specified type '{ children: string; severity: string; sx: { width: string; }; }' is not compatible with the type 'IntrinsicAttributes & RefAttributes'. The property 'children' is missing in the type 'Intri ...

Using Angular to display asynchronous data with ngIf and observables

In cases where the data is not ready, I prefer to display a loader without sending multiple requests. To achieve this, I utilize the as operator for request reuse. <div class="loading-overlay" *ngIf="this.indicatorService.loadingIndicators[this?.indic ...

Obtaining data attributes in Angular 8

I'm working with Angular 8 and I came across an issue. In my code snippet, there are two data attributes assigned to a button element, but only one attribute is showing up. Is this a syntax error or a bug? <button [attr.data-popolamento]="all" [a ...

Having trouble getting webpack to transpile typescript to ES5?

Despite following official guides and various tutorials, I am still facing an issue with compiling my code to ES5 using TypeScript and webpack. The problem is that the final bundle.js file always contains arrow functions. Here is a snippet from my webpack ...

Managing plain text and server responses in Angular 2: What you need to know

What is the best way to handle a plain text server response in Angular 2? Currently, I have this implementation: this.http.get('lib/respApiTest.res') .subscribe(testReadme => this.testReadme = testReadme); The content of lib/respApi ...

The index module is not being recognized by the NodeJS Lambda function

Struggling with setting up a lambda function in IntelliJ WebStorm using node 16, Typescript, and modules instead of plain Javascript with commonJS. After deployment, attempting to run the function results in an error: { "errorType": "Runti ...

Is there a way for me to implement a service method that retrieves the onSnapshot result, allowing me to seamlessly integrate it into my Component or Ionic Page?

Currently, I am using "ionic-angular": "3.7.1" along with Firebase Cloud Firestore. My goal is to retrieve all the documents from the Post collection whenever they are updated, deleted, or added. I have been informed that by calling the onSnapshot Method, ...

Encountered a bug in the findUnique function within the services of a Nest JS and Prisma project

I have a question about using Prisma with Nest. I keep encountering this error: src/modules/auth/auth.service.ts:28:63 - error TS2322: Type 'UserWhereUniqueInput' is not assignable to type 'string'. 28 const user = await this.prisma ...

Compatibility of Typescript with local storage

Can Typescript interact with local storage in any way? I have been setting items using the following code: localStorage.setItem('someString', JSON.stringify(MyTypescriptObject)); This method stores the object as a plain string. For example: ...

Having trouble with importing rxjs operators

After updating the imports for rxjs operators in my project to follow the new recommended syntax, I encountered an issue with the "do" operator. While switchMap and debounceTime were updated successfully like this: import { switchMap, debounceTime } ...

Nestjs gracefully shutting down upon starting the container

Whenever I try to run my container, it exits immediately. I am currently using Nestjs and Postgres in my setup. Below is the Dockerfile that I'm working with: FROM node:14.5.0 AS build WORKDIR /src RUN apt update && apt install python -y ...

Locate a specific item by its ID within a JSON file utilizing Angular version 2 or later

My JSON file structure is like the example below: { "id": "1", "country": "Brazil", "state": [ {"id": "1", "name": "Acre", "city": [ { "id": "1", "name": "Rio Branco"}, { "id": "2", "name": "Xapuri"} ...

Utilizing Angular's global interceptor functionality can streamline the process

Having trouble making 2 interceptors (httpInterceptorProviders, jwtInterceptorProviders) work globally in my lazy modules. I have a CoreModule and X number of lazy-loaded modules. Interestingly, autogenerated code by the Swagger generator (HTTP services) g ...

There was an error encountered while creating a new CLI using oclif: Subsequent variable declarations must be of the same type

I've been working on developing a new CLI tool using the oclif framework and TypeScript, but I'm encountering some issues when attempting to build the project. When I generate the CLI, it results in errors. Even when I try to manually run npm bu ...

As a quirk of TypeScript, it does not allow for returning a Tuple directly and instead interprets it as an Array

I need assistance with adding type-safe return to a general function created by a previous developer. Here is the current syntax: export function to(promise:Promise<any>) { return promise .then(data => [null, data]) .catch(err => [ ...

Tips for utilizing intellisense from monaco.d.ts

Is there a way for me to incorporate monaco.d.ts in order to utilize intellisense with the monaco-editor package? I've recently integrated this package into a JavaScript project and everything is functioning properly. However, as I transition to Type ...

Retrieve your Docusign Access Code using the typescript httpClient.post method

I am currently struggling to obtain the access token through the Docusign API. My code is producing an error in Xcode and I am unable to make it work on my native device or browser, despite successfully testing it via Postman. When attempting to run it in ...

Error: The OOP class value for translateX in the Web Animation API is returning as undefined

I'm currently working on a basic animation project using JavaScript. I have utilized the Animation class from the Web Animation API. My goal is to create multiple instances of this class in order to animate different elements with varying values and r ...