Issue: The Clerk authentication function was invoked, but Clerk was unable to detect the usage of clerkMiddleware() (or the outdated authMiddleware())

I've been following a YouTube tutorial (https://youtu.be/zgGhzuBZOQg) to create a next.js project with Clerk. However, I keep encountering error messages in the terminal every time the site loads:

 Error: Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware() (or the deprecated authMiddleware()). Please ensure the following:
-  clerkMiddleware() (or the deprecated authMiddleware()) is used in your Next.js Middleware.
- Your Middleware matcher is configured to match this route or page.
- If you are using the src directory, make sure the Middleware file is inside of it.

For more details, see https://clerk.com/docs/quickstarts/nextjs

    at stringify (<anonymous>)
    at stringify (<anonymous>)
digest: "4043468081"
 ⨯ Error: Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware() (or the deprecated authMiddleware()). Please ensure the following:
-  clerkMiddleware() (or the deprecated authMiddleware()) is used in your Next.js Middleware.
- Your Middleware matcher is configured to match this route or page.
- If you are using the src directory, make sure the Middleware file is inside of it.

For more details, see https://clerk.com/docs/quickstarts/nextjs

    at stringify (<anonymous>)
    at stringify (<anonymous>)
digest: "3666937045"
 ⨯ Error: Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware() (or the deprecated authMiddleware()). Please ensure the...

This is my middleware.ts file:

import { clerkMiddleware } from "@clerk/nextjs/server";

export default clerkMiddleware();

export const config = {
  matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
};

Project file structure: file structure

Anyone able to assist with this issue? Thank you!

I attempted relocating the middleware.ts to a newly created src folder in an attempt to resolve this error, but unfortunately, it did not work.

Answer №1

To successfully tackle this issue, I followed these steps:

  1. Initially, I halted the development server by using Control + C on macOS or CTRL + C on Windows.
  2. Subsequently, I executed the command npm run build to check for any potential build errors, thankfully finding none.
  3. Afterward, I initiated the production server with npm start and noticed that the error did not manifest in the production environment.
  4. Lastly, I restarted the development server by running npm run dev, resulting in the error disappearing from the terminal.

Although unsure of the exact resolution, this process effectively resolved the issue for me.

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

The health check URL is experiencing issues: Unable to locate any routes

I am currently developing a .net Core 2.2/Angular 8 application and recently came across the HealthCheck feature. I decided to incorporate it into my application, so here is a snippet from my Startup.cs file: using HealthChecks.UI.Client; using Mi ...

What is the process for defining an opaque type in programming?

[ This is not this ] Take a look at this snippet of code: interface Machine<OpaqueType> { get(): OpaqueType, update(t: OpaqueType); } const f = <U, V>(uMachine: Machine<U>, vMachine: Machine<V>) => { const u = uMach ...

Evolution of ReactJS state over time

When working with React, I wanted to increment a state variable called progressValue by 0.1 every 500 ms until it reaches 100. Here's what I initially tried: const [progressValue, setProgressValue] = React.useState<number>(0) const tick ...

Error: The property you are trying to set is undefined and cannot

When I attempt to set a property 'error' that is undefined, I receive a TypeError. The problematic line of code looks like this: this.error = error.code; This issue arises in an Angular Reactive Form while making a call to a web service. Below i ...

The 'prop' property is not found in the 'A | B' type

When retrieving data from a URL, if a specific condition is met, the information will be loaded into either type B or its superclass A. However, an issue arises when the data is loaded into B and TypeScript fails to recognize its properties. The code sni ...

Removing undefined elements from an array

Could somebody clarify why, in this particular scenario: const dataValues: ValueRange[] = res.data.valueRanges.filter((range: ValueRange) => range.values); const formattedValues: Array<SheetData | undefined> = dataValues.map(this.formatSheetRang ...

Create an entity with a field that holds a value type based on the value of another key field

Essentially, I am looking to create a customized "Pair" data type For example: type Pair<T extends Record<string, string | number>, K extends keyof T> = { field: K, value: T[K] } So, if we have: type Rabbit = { name: string, a ...

What methods can be used to eliminate superfluous `require(...)` or `import "...` statements while working with Rollup?

Currently, I am in the process of developing a library named share which will be utilized in various other services. To bundle this library, I have opted for Rollup.js. share serves as a common library accessed by multiple services, therefore it is essent ...

Implementing dynamic validation rules in Angular forms

In my code, there is a part where I need to make certain fields required. Initially, only the emailAddress field is required, but under a specific condition (res.isSuccess === true), I also need to set firstName, lastName, and companyName as required. The ...

Deployment to Amazon Amplify encounters failure when using Next JS

I've been encountering continuous failures while trying to deploy an SSG app on Next JS. The build consistently fails, and I'm met with an error message. Despite following the deployment documentation for SSG sites on Amazon diligently, the error ...

Error: ReferenceError - the variable 'localstorage' is not defined on this Next.js server

I have a category name stored in my localStorage. I am aware that with next.js, localStorage is only accessible on the client side and not on the server side. Despite following suggestions from stackoverflow threads discussing similar problems, I keep enco ...

`fetch` functionality does not function properly when included in middleware page after deployment on Vercel

On a specific route, I have a middleware page that first checks against the backend server. Within this middleware, I am attempting to call a next.js api page using the fetch API, which then communicates with the backend. This process functions correctly i ...

What is the best way to troubleshoot and resolve TypeScript errors related to Angular in d.ts files, especially when working

I've integrated Msal (https://github.com/AzureAD/microsoft-authentication-library-for-js) with the latest setup in Angular using Typescript 3.1.1, and I encountered the following error: ERROR in node_modules/msal/lib-commonjs/UserAgentApplication.d.t ...

Ways to retrieve specific Observable elements?

Having a function like this: getCategories(): Observable<any> { return this.category.find({where: {clientId: this.userApi.getCurrentId()}}) }; The return type of this.category.find is Observable<T[]>. When I invoke g ...

An error occurred: Unable to locate the file or assembly 'Interop.iTunesLib, Version=1.13.0.0, Culture=neutral, PublicKeyToken=null'

I've been attempting to connect to iTunes using C# programming language. The process involves creating a dll in C# and running it with TypeScript through the Overwolf API. Here's what I've done so far: Generated a .dll file I utilized the ...

Step-by-step guide on creating a personalized logic and redirecting to different pages using the useEffect hook in React or Next.js

I have recently developed a quiz application with three main pages - Junior, Senior, and SuperSenior. Depending on the selection made by the user from the dropdown menu on the homepage, I need to redirect them to the appropriate page. To achieve this func ...

Utilize Angular components in TypeScript to effectively manage errors within forms

I am currently developing a form in Angular/Typescript with more than 10 fields, and I want to streamline error management without redundancy in my HTML code. Here is an example of the form structure : <form [formGroup]="myForm"> <label&g ...

Issues arise when attempting to override attributes within the HTML of a parent component in Angular

Why does overriding an attribute in a child class that extends from another not work as expected? Here's a made-up scenario to simplify the issue: Parent class file: gridbase.component.ts import { Component, OnInit } from '@angular/core'; ...

What is the process for integrating Typescript into a Quasar 2 project that is utilizing Vite as its build tool?

The Quasar 2 documentation provides in-depth guidance on integrating Typescript with Webpack: Unfortunately, my Quasar project is configured with Vite and I am struggling to locate resources on incorporating Typescript into an already existing project. A ...

Rows in angular ag grid are vanishing when data is filtered

My ag grid includes custom components for each column, but I'm facing an issue where the components disappear when filtering the data. For example: the component inside the row To apply filtering, I use an input with a filtering function: <data-gr ...