shuding / nextra

Simple, powerful and flexible site generation framework with everything you love from Next.js.
https://nextra.site
MIT License
11.79k stars 1.28k forks source link

Improve docs for `next export` #1202

Closed shuding closed 1 month ago

shuding commented 1 year ago

Discussed in https://github.com/shuding/nextra/discussions/1197

Originally posted by **RPDeshaies** January 6, 2023 Hi, I'm currently testing using Nextra in replacement for a Vuepress project I had and I was wondering if it was possible to use the command `next build && next export` with Nextra? I've tried running the command and looking at the exported assets, but I'm getting a bunch of 404 of the static assets (js/css/etc) ![image](https://user-images.githubusercontent.com/6224111/211076260-a4ef5359-d795-4f55-a99b-813147fa55ae.png) I initially had an error about using next/images which I fixed by overriding a config in the next config, but I'm not sure at all that's the proper way of doing things. ```sh info - No "exportPathMap" found in "/next.config.js". Generating map from "./pages" Error: Image Optimization using Next.js' default loader is not compatible with `next export`. Possible solutions: - Use `next start` to run a server, which includes the Image Optimization API. - Configure `images.unoptimized = true` in `next.config.js` to disable the Image Optimization API. Read more: https://nextjs.org/docs/messages/export-image-api ``` ```tsx // next.config.js const withNextra = require("nextra")({ theme: "nextra-theme-docs", themeConfig: "./theme.config.jsx", }); module.exports = { ...withNextra(), images: { unoptimized: true, }, }; ``` Thanks in advance for the help. And also, Nextra looks absolutely fantastic, I'm really eager to make it work!
pplonski commented 1 year ago

I got the same error and switched image optimization off.

thekidnamedkd commented 1 year ago

I got the same error and switched image optimization off.

Same error as OP. Playing with next config and various solutions, but I suspect something isn't parsing between nextConfig and withNextra() on export.

@pplonski can you share your working config? Thanks!

pplonski commented 1 year ago

I just used:

// next.config.js
const withNextra = require("nextra")({
  theme: "nextra-theme-docs",
  themeConfig: "./theme.config.jsx",
});

module.exports = {
  ...withNextra(),
  images: {
    unoptimized: true,
  },
};

From what I read the yarn next export doesnt work with optimized images.

thekidnamedkd commented 1 year ago

Working for me on non-Vercel & Vercel deploys:

const nextConfig = { images: { loader: 'akamai', path: '/' } }

module.exports = withNextra(nextConfig)



  * set build commands in deploy settings to:
  ```yarn install && yarn run build```
dimaMachina commented 1 month ago

closed by https://github.com/shuding/nextra/pull/2563