Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

348
Views
NextJS Docker Container in K8s Throwing Uncaught SyntaxError: Unexpected token '<'

Creating a default NextJS typescript app with npx create-next-app@latest --ts .

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

and then a simple Dockerfile deployed to kubernetes minikube and then minikube tunnel to access the port

FROM node:alpine

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


CMD ["yarn", "dev"]

Shows a blank page with the following errors in the console when running in browser

Uncaught SyntaxError: Unexpected token '<'

However running the same image via docker run, in non k8s, works fine. I have had a look at the HTML for absolute paths as suggested in other threads and see that the path points to

http://myhost.com/_next/static/chunks/react-refresh.js?ts=1654439747173

When hovering over src

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

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

Any idea on getting it running in kubernetes?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I got it working by updating the ingress rewrite target

changing

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

to

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

and the path to

path: /(.*)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!