Using middleware is not supported when using "output: export"

After countless attempts over several days and more than a thousand combinations, I am still facing the same issue with my files.

Middleware.js:

import { NextResponse } from "next/server";

export const protectedRoutes = ["/profile", "/assets", "/profile/[id]", "/"];
export const authRoutes = ["/admin/login"];
export const publicRoutes = [];

export function middleware(request) {

console.log(request.nextUrl.pathname);

if (protectedRoutes.includes(request.nextUrl.pathname)) {
console.log("test11");
return NextResponse.redirect(new URL("/not-auth", request.url));
}

}

export const config = {
  matcher: ["/assets/:path*", "/admin/:path*"],
};

The Directory Structure:

- src
   - app
      - lib.js
      - middleware.js

next.config.mjs:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: false,
  images: {
    unoptimized: true,
  },
output: "export",
};

export default nextConfig;

Error: ⨯ Middleware cannot be used with "output: export". See more info here: https://nextjs.org/docs/advanced-features/static-html-export

[x] Compiled /favicon.ico in 2.5s (611 modules)
GET /favicon.ico 200 in 1833ms
[] Middleware cannot be used with "output: export". See more info here: https://nextjs.org/docs/advanced-features/static-html-export

I have attempted to remove the output: "export" parameter in the next.config.mjs file, but the project fails to build without it.

Answer №1

To achieve success, simply eliminate the "output": "export" line from your configuration. For your specific scenario, consider utilizing the following configuration:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: false,
  images: {
    unoptimized: true,
  },
};

export default nextConfig;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Function that solves problems through recursion

Why does the code print both dots in the array simultaneously instead of printing dot, pausing, then printing dash, and finally printing dot? Is there an issue with my conditional statement? function morseCode(code) { if (code.length === 0) { retu ...

The propagation of onClick events in elements that overlap

Having two divs absolutely positioned overlapping, each containing an onClick handler. The issue is that only the top element's onClick handler fires when clicked. React 17 is being used. Here is some sample code: <div style={{ position: "abs ...

Tips on aligning a div to the right of a headline

My goal is to have an orange circle image placed to the right of my headline <h2>. However, I am facing an issue where the circle jumps above the headline when I shrink the screen. How can I ensure that it stays on the right side no matter the screen ...

Is JSX Babel being rejected for execution?

I have recently started learning React and encountered an error while trying to run this page: Refused to execute script from 'https://unpkg.com/browse/[email protected]/babel.min.js' because its MIME type ('text/html') is not exec ...

Starting a fresh Angular project yields a series of NPM warnings, notably one that mentions skipping an optional dependency with the message: "npm

Upon creating a new Angular project, I encounter warning messages from NPM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="68e01b0d1e0d061c7518d7">[email protecte ...

What is the best way to handle authentication tokens in a Node.js server application?

One challenge I'm facing is calling an API that requires a token to be passed, and this token needs to be refreshed. The main issue is - How and where should I store a token on the server? Some solutions on the internet suggest doing something like th ...

Use Selenium IDE to click on an element using JavaScript if the stored variable equals "Yes"

I am attempting to have Selenium IDE click on a checkbox when the stored value 'x' is equal to Yes. After trying the code below, I received an error indicating that Yes is not defined. I'm also unsure which Selenium IDE command should be u ...

What is the solution for addressing a blank canvas after integrating Orbit Controls in Three.js?

Currently, I am working on learning three.js, and my progress has been going well. I successfully programmed a cube on the canvas using JS Fiddle. However, when I attempted to implement Orbit Controls to rotate the cube, the canvas displayed only a black s ...

Improprove the Express Router in a Node.js application

Is there a way to avoid repeating the isUserAuth and isAdminAuth middleware on each endpoint? Can I apply them just once so they work for all routes without having to specify them individually? const { createBranch, getAllBranch, getBranch } = require(&apo ...

Choosing a single radio button value within a nested ng-repeat loop in AngularJS

Help needed with selecting only one radio button value in nested ng-repeat. Please review the source code and suggest any potential mistakes. <form ng-submit="save()"> <div ng-repeat="x in surveyLst"> <div class="row"> < ...

Exploring the power of NativeScript and Angular 2's HTTP service

I am currently learning about native apps using JavaScript technologies and I am attempting to create a simple application utilizing the Pokemon API. Progress So Far I have developed a basic component that shows a list of pokemons retrieved from an HTTP ...

Using Rails and Haml to Implement Smooth Scrolling with Jquery and CoffeeScript

Looking to accomplish a straightforward task using CoffeeScript, Rails, and Haml. While I don't have much experience with CoffeeScript, I'm eager to experiment. The goal is to have the view scroll to a specific div id when a button is pressed. A ...

AJAX: Building a Robust Single Page Application with Enhanced Security

Currently, I am developing a web/mobile application using AJAX. This app consists of 4 pages: the login page and three protected pages that are only accessible to logged-in users. My plan is to implement the Single Page Application pattern, where all 4 pa ...

Having trouble getting Angular Filter to work within a directive expression?

I am currently working on a directive where I need to convert both the attribute and object name values to lowercase. I have tried using filters, as well as the $filter service, but it doesn't seem to be working. Can anyone please provide assistance i ...

What is the best way to conceal or eliminate slider increments and their corresponding labels in plotly.js?

Is there a way to eliminate or conceal the step ticks and labels of the animation slider? I want to get rid of the slider's step markers (ticks) and the corresponding labels: 'Red', 'Green' and 'Blue' located beneath the ...

Implementing ng-show based on a specific position on a webpage

I am a beginner in AngularJS and I'm struggling to understand how to customize ng-show/ng-hide. I want the navigation bar below to only appear once the user has scrolled 600px down the page, but since I can't use jQuery with Angular, I'm uns ...

Whenever the page is refreshed, the vertical menu bar with an accordion feature hides the sub

I have designed a vertical accordion menu bar following the example at http://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_accordion_symbol However, I am encountering an issue where clicking on a button to display a submenu causes the page to refr ...

Leverage the power of Next.js Dynamic routing query object with an SWR fetch request

While working with Next.js dynamic routing, I am facing an issue where my SWR fetch request is being called before the query object is properly set. This occurs specifically when using the routing query object. Let's take the example of a dynamic rou ...

Using local variables from an external HTML file within an AngularJS directive template

Just making sure I am wording my question correctly, but I have not been able to find any information on this specific topic. Imagine I have an AngularJS directive that looks something like this: angular.module( 'example', [] ).directive( ...

obtain every drop-down choice from Angular 2's selectiongetConfig() function

Within the document, there is a select element as shown below: <select tabindex="1" size="5" name="abc" multiple> <option value>Select a value.</option> <option value>option 1</option> <option value>option 2 ...