Next.js 14 Production Issue: TypeError on 'READY' property - Need Assistance
Answered
American black bear posted this in #help-forum
American black bearOP
Hello Next.js and JavaScript communities,
I am currently facing a perplexing issue with my Next.js application (version 14.1.0) that's only occurring in production mode. The application runs smoothly in a development environment, but the production deployment is encountering a TypeError that I'm struggling to resolve.
Error Description:
javascript
Copy code
TypeError: Cannot read properties of undefined (reading 'READY')
at i (/home/app/.next/server/chunks/4221.js:1:37706)
...
This error seems to stem from a chunk file in the Next.js build, but the exact cause is elusive.
Environment Details:
Operating System: Linux (Ubuntu), platform: linux, arch: x64
Node Version: 18.19.0
NPM Version: 10.2.3
Yarn Version: 1.22.19
Next.js Version: 14.1.0
React/React-DOM: 18.2.0
Deployment: Digital Ocean Droplet inside Docker
Other Notes: The issue is not reproducible in a local production build or in the development environment.
I've checked for compatibility issues and have ensured that all dependencies are up to date. Given that the error does not occur in development, I suspect it might be related to the production build process or a specific environment configuration within Docker.
If anyone has encountered a similar issue or has insights into potential causes, your advice would be greatly appreciated. I'm particularly interested in any Docker-specific configurations or limitations that might affect Next.js applications, or any known issues with the mentioned versions of Node, Next.js, or React.
Thank you in advance for your time and help!
I am currently facing a perplexing issue with my Next.js application (version 14.1.0) that's only occurring in production mode. The application runs smoothly in a development environment, but the production deployment is encountering a TypeError that I'm struggling to resolve.
Error Description:
javascript
Copy code
TypeError: Cannot read properties of undefined (reading 'READY')
at i (/home/app/.next/server/chunks/4221.js:1:37706)
...
This error seems to stem from a chunk file in the Next.js build, but the exact cause is elusive.
Environment Details:
Operating System: Linux (Ubuntu), platform: linux, arch: x64
Node Version: 18.19.0
NPM Version: 10.2.3
Yarn Version: 1.22.19
Next.js Version: 14.1.0
React/React-DOM: 18.2.0
Deployment: Digital Ocean Droplet inside Docker
Other Notes: The issue is not reproducible in a local production build or in the development environment.
I've checked for compatibility issues and have ensured that all dependencies are up to date. Given that the error does not occur in development, I suspect it might be related to the production build process or a specific environment configuration within Docker.
If anyone has encountered a similar issue or has insights into potential causes, your advice would be greatly appreciated. I'm particularly interested in any Docker-specific configurations or limitations that might affect Next.js applications, or any known issues with the mentioned versions of Node, Next.js, or React.
Thank you in advance for your time and help!
Answered by Ray
maybe try this and use standalone output
https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
20 Replies
American black bearOP
Hi @Ray thanks for responding. The error appears in server console.
And in browser i get 500 internal server error
@American black bear Hi <@743561772069421169> thanks for responding. The error appears in server console.
is that the full error message?
American black bearOP
Yes, and it repeats
TypeError: Cannot read properties of undefined (reading 'READY')
at i (/home/app/.next/server/chunks/4221.js:1:37706)
at /home/app/.next/server/chunks/4221.js:1:9030
at Object.ns [as useMemo] (/home/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:40843)
at t.useMemo (/home/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109391)
at j (/home/app/.next/server/chunks/4221.js:1:8995)
at nM (/home/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:47419)
at nN (/home/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:64674)
at nO (/home/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:46497)
at nM (/home/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:47235)
at nN (/home/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:64674)American black bearOP
Yes, It works, we have not been able to reproduce it locally (both in dev and prod) mode also cant reproduce it in server in dev mode
and how does your Dockerfile look like?
American black bearOP
It only happens in server in prod mode
Dockerfile
FROM node:18-alpine AS base
RUN mkdir -p /home/app/ && chown -R node:node /home/app
WORKDIR /home/app
USER node
COPY --chown=node:node package*.json ./
RUN npm install --frozen-lockfile
COPY --chown=node:node . .
FROM base AS build
ENV NODE_ENV=production
WORKDIR /build
COPY --from=base /home/app/ ./
RUN npm run build
FROM node:18-alpine as production
ENV NODE_ENV=production
WORKDIR /home/app
COPY --from=build /build/package*.json ./
COPY --from=build /build/.next ./.next
COPY --from=build /build/public ./public
COPY --from=build /build/.env.production ./.env.production
RUN npm install next
EXPOSE 3000
CMD ["npm", "start"]@American black bear Dockerfile
FROM node:18-alpine AS base
RUN mkdir -p /home/app/ && chown -R node:node /home/app
WORKDIR /home/app
USER node
COPY --chown=node:node package*.json ./
RUN npm install --frozen-lockfile
COPY --chown=node:node . .
FROM base AS build
ENV NODE_ENV=production
WORKDIR /build
COPY --from=base /home/app/ ./
RUN npm run build
FROM node:18-alpine as production
ENV NODE_ENV=production
WORKDIR /home/app
COPY --from=build /build/package*.json ./
COPY --from=build /build/.next ./.next
COPY --from=build /build/public ./public
COPY --from=build /build/.env.production ./.env.production
RUN npm install next
EXPOSE 3000
CMD ["npm", "start"]
maybe try this and use standalone output
https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
Answer
American black bearOP
Ok, let me give it a try
@American black bear Ok, let me give it a try
FROM node:18-alpine AS base
RUN mkdir -p /home/app/ && chown -R node:node /home/app
WORKDIR /home/app
USER node
COPY --chown=node:node package*.json ./
RUN npm install --frozen-lockfile
COPY --chown=node:node . .
FROM base AS build
ENV NODE_ENV=production
WORKDIR /build
COPY --from=base /home/app/ ./
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]or try this first
American black bearOP
Its is building
American black bearOP
It is working now!
It was dumb of us not to think about we are copying over local build files!
Thanks Ray!
@Ray maybe try this and use standalone output
https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
no prob, you might want to follow this config to build a standalone output
American black bearOP
Will definitely do! thanks again.