19

I’ve built a Next.js app, and I wanted to use static exporting to host the project on my hosting. The app is simple, so I didn’t use most of the features that Next.js offers. When I run: npm run build (next build && next export) i get .next folder and out folder which has the following folders: /static /chunks /css /media

I have all the needed settings (ie: output: "export", in next.config.js..)

I'm supposed to get all the static HTML files..but i haven’t get those, any solutions please?


Update:

This happened because image optimization is active and works under the hood,for that the app has to run on a server but i'm trying to generate a static website, i disabled it by adding the following to next.config.js:

module.exports = {
  images: {
    unoptimized: true,
  },
}

And it worked as expected.

4
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Mar 20, 2023 at 13:49
  • 3
    @Celsiuss The question is pretty clear, I have the exact same issue of NextJs not generating any html files after the static export. Commented Sep 1, 2023 at 1:13
  • @khaled after disabling the image-optimization, it also generated the correct html files for me, although I still need some sort of http server, because the html files use leading / in all urls and file:// protocol doesn't handle that properly. Commented Sep 1, 2023 at 1:19
  • 2
    As mentioned in the Update section, images.unoptimized = true fixed this issue. Commented Nov 13, 2023 at 12:11

2 Answers 2

5

I know its late replay but this may help someone else.

I can see the HTML files in out folder when I disable the image optimization in next.config.js.

const nextConfig = {
  output: 'export',
  reactStrictMode: true,
  swcMinify: true,
  images: {
    unoptimized: true,
  },
}

Somehow the image optimization was causing issues with HTML generation.

The successful build should show generated files like the once below. Console output of next build with successful HTML generation

Refer to this issue: https://github.com/vercel/next.js/issues/40240#issuecomment-1237549085

Sign up to request clarification or add additional context in comments.

Comments

-3

The output of next export doesn't necessarily include an index.html file.

There will be one HTML file for each file inside the /pages folder.

E.g. if you have a file /pages/start.js, then there will be a file inside the output folder: /out/start.html.

Only if you have a file /pages/index.js, then there will also be a /out/index.html file.

1 Comment

I have /pages/index.js and /pages/posts/first-post.js, but still I don't have any html file in the the out folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.