-
Notifications
You must be signed in to change notification settings - Fork 27.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All static assets (js/css/media) in Standalone mode become 404 #49283
Comments
I am having the exact same issue |
same issue here |
next version "12.2.3" same issue here. |
Any solutions or idea about this? I have the same issue on v13.3.0. |
I used this instead works much better.. https://nextjs.org/docs/pages/building-your-application/configuring/custom-server not sure what Standalone mode is meant for |
I faced this issue today, I just found a workaround for this: copy .next/static to .next/standalone/.next/static |
Looking at the docs it seems that this is intended behavior: “ This minimal server does not copy the public or .next/static folders by default as these should ideally be handled by a CDN instead, although these folders can be copied to the standalone/public and standalone/.next/static folders manually, after which server.js file will serve these automatically.” https://nextjs.org/docs/pages/api-reference/next-config-js/output |
Yeah this is intended behavior as per the documentation for the |
Confusingly, it seems you need to write your own script copy these assets over to the build folder yourself. An opt-in that would allow the Next build to do this for you would be nice if a CDN wasn't configured to serve these assets |
Sharing the script I had to write to make this work ( "scripts": {
"deploy": "next build && mkdir -p dist/standalone/public/_next && cp -r dist/static dist/standalone/public/_next/"
},
|
The script that works
go to standalone folder |
Having the same issue. Using next 13.0.6. |
As far as I can tell, this is not a code issue, but maybe a documentation issue. If you look at the example dockerfile that uses I shortened it into a working docker example for myself. (note that
|
感谢非常有用 |
Can confirm, works with Next 13 for me. |
Copying the assets manually works, yeah. I just don't think everyone will want to host them on CDNs. Could we perhaps get a config option that controls whether or not these assets are copied to the standalone folder? |
I am facing the same issue here, tried with Dockerfile: FROM node:18-alpine
ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
WORKDIR /app
RUN mkdir .next
RUN chown nextjs:nodejs /app
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --chown=nextjs:nodejs public ./public
COPY --chown=nextjs:nodejs dist/standalone ./
COPY --chown=nextjs:nodejs dist/static ./.next/static
USER nextjs
EXPOSE 80
ENV PORT 80
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"
CMD ["node", "server.js"]
/app $ find . -maxdepth 2 -type d
.
./.next
./.next/static
./public
./public/flags
./public/icons
./public/img
./dist
./dist/server
./dist/cache
./node_modules
./node_modules/@next
./node_modules/@swc
./node_modules/busboy
./node_modules/caniuse-lite
./node_modules/client-only
./node_modules/glob-to-regexp
./node_modules/graceful-fs
./node_modules/nanoid
./node_modules/next
./node_modules/picocolors
./node_modules/react
./node_modules/react-dom
./node_modules/scheduler
./node_modules/source-map-js
./node_modules/streamsearch
./node_modules/styled-jsx
./node_modules/watchpack Everything under
What am i doing wrong ? |
Ok i found it:
IF you specify a custom So in my case with a configuration like this: /** @type {import('next').NextConfig} */
const nextConfig = {
images: {
domains: [
process.env.NEXT_IMAGE_DOMAIN,
process.env.NEXT_CDN_IMAGE_DOMAIN,
],
},
distDir: "dist",
output: "standalone",
};
module.exports = nextConfig; The working paths must be this: /app $ find . -maxdepth 2 -type d
.
./.next
./public
./public/flags
./public/icons
./public/img
./dist
./dist/server
./dist/static
./dist/cache
./node_modules
./node_modules/@next
./node_modules/@swc
./node_modules/busboy
./node_modules/caniuse-lite
./node_modules/client-only
./node_modules/glob-to-regexp
./node_modules/graceful-fs
./node_modules/nanoid
./node_modules/next
./node_modules/picocolors
./node_modules/react
./node_modules/react-dom
./node_modules/scheduler
./node_modules/source-map-js
./node_modules/streamsearch
./node_modules/styled-jsx
./node_modules/watchpack I lost 4 hours of my life for this. |
This solution not worked for me! I have https://example/subpath and whe i deploy my app, all the assets _next/static is being pointed to https://example/_next/static and returning 404. My version is Next 14.0.4. Could you help me please to setup this under ngnix-proxy-manager? |
I'm also facing this issue with v14.0.4 |
This. The bugThere is actually a bug in the documentation: https://nextjs.org/docs/app/api-reference/next-config-js/output
It should be noted here that This is crucial when changing Proposed solutionTo mitigate this issue I propose to hardcode third level dist to .next, that is to always have: ./<distDir>/standalone/.next/static ReasoningI know that top level dist may be important when one wants to deploy to different providers, but third level dist in the standalone directory is just an internal directory for |
I got a similar error to the one above and tried most of the solutions here, but they didn't solve the problem for me. Finally, for the standalone build, I was able to provide a solution by copying in my own project as follows. Everything is fine now. FROM node:18-alpine AS builder
WORKDIR /app
RUN apk add --no-cache libc6-compat
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN npm install --loglevel verbose
COPY . .
RUN npm run build
FROM node:18-alpine AS runner
WORKDIR /app
#ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN mkdir .next
RUN chown nextjs:nodejs .next
COPY --from=builder --chown=nextjs:nodejs /app/dist/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/dist/.next/static ./dist/.next/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
#COPY --from=builder --chown=nextjs:nodejs /app/dist/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD HOSTNAME="0.0.0.0" node server.js I copied |
Did you find a way to get rid of this problem ? |
Thanks, this worked for me! Using here:
|
the files in .next/static need to be copied to .next/standalone/.next - ref vercel/next.js#49283 (comment) Added relevant copy command to build script in package.json
I'm still having that issue: https://github.com/hendisantika/nextjs-mysql-product-crud |
Hi I have stumbled on this problem myself and my app I am deploying in an Azure container and it works fine (everything loads), but if I try to access my app from a Terraform/ingress domain, I get all 404s e.g if the domain is I have tried the Dockerfiles here but no luck... Does anyone have any suggestions? I am not using a custom distDir. EDIT: For anyone testing the solutions above and not getting anywhere and using Ingress/Kube to direct to their app through another domain: check if your requests are being made to |
I am on self-hosting, not using vercel service. I faced this issue today. Fortunately, it turned out that the _next/static/media folder was ignored by git. So, just excluded that in the .gitignore file and it's working like charm. |
This comment has been minimized.
This comment has been minimized.
i was working with the turbo repo with standalone next app, i got it working👍
|
Hi everyone— The static files are The minimal server does not copy the public or .next/static folders by default as these should ideally be handled by a CDN instead, although these folders can be copied to the standalone/public and standalone/.next/static folders manually, after which server.js file will serve these automatically. To copy these and then start this local minimal server locally, you can do something like this:
I have also just created a PR to update our documentation with this → #72432. I see that other folks have already figured out solutions for this. I will closing this PR since this is a non-issue! |
Beware the static files should not always be inserted to the standalone folder, they should actually go into the folder where the project resides which may be different in monorepos. For example, in our case:
|
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Standalone mode (output: "standalone")
Link to the code that reproduces this issue
asdf
To Reproduce
next.config.js
Run:
npm run build
Run:
node .next/standalone/server.js
Open
http://localhost:3000
Describe the Bug
All js and css files become 404
p://localhost:3000/_next/static/css/36abb935a2bfb1bb.css net::ERR_ABORTED 404 (Not Found)
p://localhost:3000/favicon.ico 404 (Not Found)
p://localhost:3000/_next/static/chunks/main-764a718264343ae9.js net::ERR_ABORTED 404 (Not Found)
etc
Expected Behavior
It can find and load all js/css files
Which browser are you using? (if relevant)
Latest Chrome
How are you deploying your application? (if relevant)
IISNode
The text was updated successfully, but these errors were encountered: