Replies: 4 comments 2 replies
-
Hi! I've seen this error before... . Here's a comprehensive solution: Quick FixFirst, try clearing your cache and reinstalling: # Clear everything
rm -rf node_modules .next
rm package-lock.json # or yarn.lock/pnpm-lock.yaml
# Reinstall
npm install Common Causes & Solutions1. Missing or Corrupted Next.js Installation# Verify Next.js is installed
npm list next
# Reinstall if needed
npm install next@latest react@latest react-dom@latest 2. Turbopack Compatibility IssueIf the error persists, try running without Turbopack while we troubleshoot: next dev # instead of next dev --turbo 3. Package Manager ConflictsMake sure you're using only ONE package manager: # If using npm
rm yarn.lock pnpm-lock.yaml
# If using yarn
rm package-lock.json pnpm-lock.yaml
# If using pnpm
rm package-lock.json yarn.lock 4. Node VersionEnsure you're using Node.js 18.17 or later: node --version 5. Monorepo SetupIf you're in a monorepo, ensure Next.js is properly hoisted or installed in your workspace: # For npm workspaces
npm install next@latest -w your-app-name
# For yarn workspaces
yarn workspace your-app-name add next@latest Still Having Issues?Please share:
This will help in coming up with more specific solution. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Naive follow up, but is |
Beta Was this translation helpful? Give feedback.
-
you're right @icyJoseph here is quick follow up on last solution -
Solution: Pass Build Args Explicitly1. Update DockerfileFROM node:18-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
RUN yarn install --frozen-lockfile
# Copy source including .env.loc
COPY . .
# CRITICAL: Set build-time env var explicitly
ARG NEXT_PUBLIC_STATIC_HOST
ENV NEXT_PUBLIC_STATIC_HOST=$NEXT_PUBLIC_STATIC_HOST
# Build with the env var available
RUN yarn build:loc
# Runtime stage
FROM node:18-alpine AS runner
WORKDIR /app
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/.env.loc ./.env.loc
EXPOSE 3000
CMD ["yarn", "start:loc"] 2. Build Command# Extract value from .env.loc and pass as build arg
export NEXT_PUBLIC_STATIC_HOST=$(grep NEXT_PUBLIC_STATIC_HOST .env.loc | cut -d '=' -f2)
docker build --build-arg NEXT_PUBLIC_STATIC_HOST=$NEXT_PUBLIC_STATIC_HOST -t your-app . 3. Verify It's WorkingAdd this to your console.log('Building with assetPrefix:', process.env.NEXT_PUBLIC_STATIC_HOST);
module.exports = {
assetPrefix: process.env.NEXT_PUBLIC_STATIC_HOST || '',
// your other config...
} Alternative: Load .env.loc During BuildIf you prefer using env-cmd as-is: # In builder stage, ensure env-cmd loads the file
RUN npx env-cmd -f .env.loc node -e "console.log('NEXT_PUBLIC_STATIC_HOST:', process.env.NEXT_PUBLIC_STATIC_HOST)"
RUN npx env-cmd -f .env.loc yarn build Quick TestAfter building, check if assets have the prefix: docker run --rm your-app grep -r "your-cdn-url" .next/ This ensures the CDN URL is baked into the build output. |
Beta Was this translation helpful? Give feedback.
-
We use a bash script before start up to replace a placeholder text in nextjs output, as explained here; #18301. Do make sure it's something VERY VERY distinguishable, so you don't replace anything accidentally |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm using
Next.js version 14.2.16
When I run yarn build:loc and yarn start:loc locally on my machine, everything works fine.
all files, including CSS and JS, are correctly loaded with the assetPrefix from env that NEXT_PUBLIC_STATIC_HOST
However, when I build the project using Docker and run it, some files (like CSS and some JS chunks) are not loaded with the correct assetPrefix. I’m not sure why this is happening.
Here’s some context
Does anyone know why assetPrefix might not be applied properly in the Docker environment even though it works locally?
Thanks in advance!
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions