typescriptnext.jsclerk

"@clerk/nextjs/server"' has no exported member named 'clerkMiddleware'


I am working on Nextjs 14 with typescript and I am trying to use clerk for authentication and authorization. When I created the app using the clerk docs I was said to write the following code in middleware.ts

import { authMiddleware } from "@clerk/nextjs";

export default authMiddleware({});

export const config = {
    matcher: ["/((?!.+.[w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};

Then after sometime when I went to apply protected routes in the clerk documentation I found :

This method is now deprecated. Please use clerkMiddleware() instead.

the docs: https://clerk.com/docs/references/nextjs/auth-middleware

When I wrote this in my middleware.ts I get the error in the title:

'"@clerk/nextjs/server"' has no exported member named 'clerkMiddleware'. Did you mean 'WithClerkMiddleware'?ts(2724)

I have also used

npm i clerk@latest

How should I solve the error


Solution

  • It looks like there is a typo in the package name you're trying to install. To resolve the issue, you should update to version 5.0.0 or newer, which includes the clerkMiddleware function. You can update the package by running the following command in your terminal:

    npm i @clerk/nextjs@latest