Chanpreet kaur
Chanpreet kaur

Reputation: 43

"@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

Upvotes: 3

Views: 3853

Answers (4)

Ntwanano Rikhotso
Ntwanano Rikhotso

Reputation: 23

reference link: https://clerk.com/docs/references/nextjs/clerk-middleware

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

Upvotes: 0

rob_was_taken
rob_was_taken

Reputation: 413

Clerk now has a Core-2 (from version 5 onwards)

There is an upgrade guide here: https://clerk.com/docs/upgrade-guides/core-2/nextjs

With this installed: "@clerk/nextjs": "^5.0.3", I can now use these methods without errors.

import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';

Upvotes: 1

Anish Arya
Anish Arya

Reputation: 432

try using this version of clerk: "@clerk/nextjs": "^4.29.12" with the middleware that u wrote. it should work. I am using the same in my project.

Upvotes: 2

Jordan Marcus
Jordan Marcus

Reputation: 56

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   

Upvotes: 4

Related Questions