Next.js Discord

Discord Forum

⨯ Middleware cannot be used with "output: export".

Answered
Schweizer Laufhund posted this in #help-forum
Open in Discord
Avatar
Schweizer LaufhundOP
My current next.config
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: "export", // Outputs a Single-Page Application (SPA).
  distDir: "./dist", // Changes the build output directory to `./dist/`.
  webpack: (config) => {
    config.externals.push("@node-rs/argon2", "@node-rs/bcrypt");
    return config;
  },
};

export default nextConfig;

What do I change? I have auth middleware (lucia)

17 Replies

Answer
Avatar
I think you're using the wrong export for the job here
Basically, setting output: export turns your app into a completely static HTML/CSS application, like an oldschool style app
I'm simplifying a bit, but that's the general gist
Naturally, when compiling your complex React application with auth, etc, to a completely static app that you can run on anything, you lose a ton of functionality
The export output type is usually for if you're making some kind of website with little to no interaction, essentially like you're making an old school HTML app, but you want to write it in react because of the developer experience.
If I had to guess, and given you're using Lucia auth, I think the output type you're looking for is output: standalone
That's typically what I see on most production apps, and should support your middleware just fine 🙂
Avatar
100% correct, output: "export" indicates that its a static export, you can have something thats static with middleware.
Avatar
sorry just sanity checking, did you mean can't? want to make sure I'm not off base
Avatar
Yeah it’s “can’t”
Avatar
roger, thank y'all 🙏
Avatar
Sorry 😦
Avatar
nothing to be sorry about at all, honestly was just sanity checking to make sure I didn't just answer with a wall of lies 😂
still relatively new to next myself
Avatar
All good, I was happy to see someone else giving a good comprehensive answer then I came in and put doubt in everyones mind 😄
Avatar
Schweizer LaufhundOP
thanks this worked