Encountering Uncaught SyntaxError while Running NextJS Docker Container in Kubernetes due to Unexpected Token "<"

Trying out a default NextJS typescript app creation using

npx create-next-app@latest --ts .

 "next": "12.1.6",
 "react": "18.1.0",
 "react-dom": "18.1.0"

Followed by a basic Dockerfile setup for deployment on kubernetes minikube with minikube tunnel to access the port

FROM node:alpine

WORKDIR /app
COPY package.json .
RUN yarn install
COPY . .


CMD ["yarn", "dev"]

Encountering a blank page and console errors when running the app in a browser

Uncaught SyntaxError: Unexpected token '<'

The same image runs smoothly via docker run outside of kubernetes. Checked HTML for paths, pointing to:

While hovering over src

<div id="__next">
<script src="/_next/static/chunks/react-refresh.js?ts=1654439747173"></script>

Including deployment.yaml and ingress files

apiVersion: apps/v1
kind: Deployment
metadata:
 name: front-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: front
  template:
    metadata:
      labels:
        app: front
    spec:
      containers:
        - name: front
          imagePullPolicy: Never
          image: mine/front:latest
          resources:
           limits:
            memory: 512Mi
            cpu: "1"
---
apiVersion: v1
kind: Service
metadata:
  name: front-service
spec:
  selector:
    app: front
  ports:
    - name: front
      protocol: TCP
      port: 3000
      targetPort: 3000


// ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
    - host: myhost.com
      http:
        paths:
          - path: /?(.*)
            pathType: Prefix
            backend:
              service:
                name: front-service
                port:
                  number: 3000

Seeking solutions to run the application successfully on kubernetes environment

Answer №1

After some adjustments, I managed to get it functioning properly by updating the ingress rewrite target.

Modifying:

nginx.ingress.kubernetes.io/rewrite-target: /$2

to:

nginx.ingress.kubernetes.io/rewrite-target: /$1

and adjusting the path to:

path: /(.*)

Answer №2

I encountered a similar issue with my ingress file mirroring yours, resulting in an error. In my setup, both the UI and /backend had default routes creating conflict. To resolve this, I excluded the UI from the main ingress file and set up a separate one specifically for the UI, which successfully resolved the problem. However, I'm still puzzled as to how this routing issue impacted changing a JavaScript file in Webpack.

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

The Docker container is encountering issues after initialization (node:19). An unhandled promise rejection warning is being displayed, indicating that the error has exited with code 3

When I run docker build . -t app, followed by docker run -p 8080:8080 app, either my Docker container or node seems to be throwing an error that's preventing me from viewing my app. Normally, when running my node app locally, I just use npm run dev an ...

Is Angular automatically assigned to `window.angular` on a global level when it is loaded as a CommonJS module?

When I import Angular 1.4 in my Webpack build entry point module as a CommonJS module using var angular = require("angular");, it somehow ends up being accessible in the global namespace of the browser (as window.angular). Upon examining the source code o ...

Sending JSON data to Vue using HTML attributesHere's a guide on how you can pass JSON

How can I successfully pass JSON data via an HTML attribute in Vue.js? <div id="app" data-number="2" data-json="{"name":"John", "age":30, "car":null}"></div> In my main.js ...

Tips for including a hashtag in an AJAX request

When using ajax to send messages to the server in my chat application, I encountered an issue where everything after a hashtag is omitted. I attempted to address this by encoding the message, but it resulted in other complications in the PHP code. The enco ...

React useEffect not working when using the default state

I'm currently facing an issue where setting the page to its default value from the refresh function does not trigger the useEffect hook on the first attempt. However, if I run the refresh function for the second time, it works fine. Interestingly, thi ...

Just because it's easy doesn't mean it will make a difference in the

I seem to be overlooking something quite simple, but alas, it eludes me. The code I have written is as follows: var count = 0; $(document).on('click', button, function() { var originalLink = button.attr('href'), ...

Guide to presenting JSON data with ajax

I am trying to dynamically display data based on the selected value from a drop-down list using Ajax's GET method. The idea is to modify the URL by appending the selected item in order to retrieve relevant data from the server: Here is an example of ...

Cross browser array filtering in javascript

I'm facing a challenge that I haven't been able to find a solution to yet. I have an array, let's say var oldArr=['one','two','3'];, and I need to create a new array containing only the string values. Currently, ...

Algorithm to assess date equivalence and provide a boolean response to the calendar

Currently, I am working on implementing a logic for a calendarpicker component. This component includes a disabledDateCallback event parameter that provides a date as input. My task is to develop a logic that will allow me to disable all dates retrieved ...

The jQuery function fail() is triggered when the Flickr API fails to return data

I have been troubleshooting an issue with the Flickr Api url. It appears to return data correctly for my images when accessed directly, but I am encountering difficulties when trying to include it in $.ajax() and $.getJson(). The data does not load and the ...

JavaScript code in AJAX response functions properly in browsers like Firefox, Chrome, and Opera. However, it encounters issues in Internet Explorer 11, displaying an error message stating

After searching through various posts, I was unable to find a solution to my question. My query involves requesting a jQuery Datepicker via AJAX. I have provided an example for you to review in Firefox, Chrome or Opera: Ajax javascript example Unfortuna ...

Next.js Update: Adjusting the response

Utilizing the rewrite feature in Next.js, I am aiming to intercept responses and modify headers and links within the body. In my front-facing Next.js web app, there are elements sourced from a different service that should be hidden from visitors. The goa ...

Printing a distinct and ever-changing value on an HTML page using Angular 4's *ngFor directive

Recently, a client asked me to create draggable div elements in a loop. To achieve this task, I utilized angular2-draggable. Initially, the drag feature worked on a single static div element, like this: <div ngDraggable [handle]="DemoHandle" class="ca ...

Retrieve the HTML location of each element stored in a database using JavaScript

I have a scenario where I am fetching elements from a PHP database and my objective is to modify the style of the HTML tags containing them when they are hovered over using JavaScript. However, I am facing an issue where this functionality only works for t ...

Warning: Shadcn-UI Form Alert - An element is converting an uncontrolled input to controlled mode

Throughout the course of this project, I found myself repeatedly using const [fileNames, setFileNames] = useState<string[]>([]); and logging the state with console.log(fileNames). However, every time I clicked on the parent element, an empty Array e ...

What is the best way to display information in a Handlebars template file?

Having trouble displaying data in the template using NestJS with mysql. Here is the code snippet from controller.ts: import { Controller, Get, Post, Put, Delete, Body, Param, Render, UsePipes, Logger, UseGuards} from '@nestjs/common'; import { P ...

Check out the selected values in Ionic 3

I am trying to retrieve all the checked values from a checkbox list in an Ionic3 app when clicked. Below is the code snippet: <ion-content padding> <ion-list> <ion-item *ngFor="let item of items; let i= index"> <ion-label>{{i ...

What is the best way to invoke an HTML file using a jQuery function in a JavaScript file?

When I call an HTML file from a jQuery function using require(), I am encountering an issue where I am unable to link the CSS with the HTML file. After running the file, only plain HTML is displayed without any styling. The structure of my HTML file is as ...

Enhancing features with jQuery's .animate() function

Can anyone help me figure out why the div on the right is not pushing itself away from the one on the left when I hover over it? I want it to move on mouseenter and return to its original position on mouseleave. The changing background colors are just ther ...

Form a column containing both row object data and html code elements

I am in the process of creating a unique column within my table, allowing me to execute specific actions and generating HTML code based on the object defining the row. Being new to Angular, I believe I should utilize $compile, but I am unsure of how to pr ...