Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

357
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda