Error message encountered in Next.js when trying to import 'SWRConfig' from 'swr': ClerkProvider Error. The import is not successful as 'SWRConfig' is not exported from 'swr

I recently started working on a new Next.js project and integrated Clerk into it. I set up the env.local and middleware.ts files before wrapping the HTML div with ClerkProvider. However, when attempting to run the project locally, I encountered the following error:

⨯ ./node_modules/@clerk/shared/dist/react/index.mjs
Attempted import error: 'SWRConfig' is not exported from 'swr' (imported as 'SWRConfig').

Import trace for requested module:
./node_modules/@clerk/shared/dist/react/index.mjs
./node_modules/@clerk/clerk-react/dist/index.mjs
./app/layout.tsx
GET / 500 in 2222ms

Below is the code snippet causing the issue:

import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { ClerkProvider, SignedIn, SignedOut, SignInButton, UserButton } from "@clerk/clerk-react";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <ClerkProvider>
      <html lang="en">
        <header>
            <SignedOut>
              <SignInButton />
            </SignedOut>
            <SignedIn>
              <UserButton />
            </SignedIn>
          </header>
        <body className={inter.className}>{children}</body>
      </html>
    </ClerkProvider>
  );
}

The VSCode's "Problems" tab flags the following issue:

[{
    "resource": "/c:/Users/Owner/OneDrive/Desktop/GitHub/budget-tracker/app/layout.tsx",
    "owner": "typescript",
    "code": "2322",
    "severity": 8,
    "message": "Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes & ClerkProviderProps'.\n  Type '{ children: Element; }' is missing the following properties from type 'Without<{ routerPush: RouterFn; routerReplace: RouterFn; routerDebug?: boolean | undefined; } & SignInForceRedirectUrl & SignInFallbackRedirectUrl & ... 5 more ... & { ...; }, \"isSatellite\">': routerPush, routerReplace",
    "source": "ts",
    "startLineNumber": 19,
    "startColumn": 6,
    "endLineNumber": 19,
    "endColumn": 19
}]

I have been unable to find any relevant information online regarding this specific issue.

Answer №1

Ensure you update the import statement to:

import { ClerkProvider, SignedIn, SignedOut, SignInButton, UserButton } from "@clerk/nextjs";

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

Error TS7053 occurs when an element is given an 'any' type because a 'string' expression is being used to index an 'Object' type

When attempting to post data directly using templateDrivenForm and retrieve data from Firebase, I encountered the following type error message. Here are the relevant parts of my code: // Posting data directly using submitButton from templateDrivenForm onC ...

Array of generic types in Typescript

Here's a method that I have: getFiveObjectsFromArray(array: T[]) { return array.slice(0, 5); } I've been using this method multiple times. Is there a way in TypeScript to pass a generic argument instead of using multiple types? Also, when ...

Tips for effectively sending prop to a component in React with the help of TypeScript

Hey there, I'm working on a component called FormField which can accept either an icon for create or edit. Currently, I am using this FormField inside another component called SelectWithFormField. Here's how it looks: const FormField = ({create, ...

Developing an Angular 11 Web API Controller with a POST Method

I am in need of creating or reusing an object within my web API controller class to send these 4 variables via a POST request: int Date, int TemperatureC, int TemperatureF, string Summary Currently, I am utilizing the default weather forecast controller t ...

React error message: "Cannot update state on a component that is not mounted" unless using the useEffect hook

(I am a beginner using Next.js + Styled Components and need help :)) I'm currently working on creating a "Netflix" style page, with unique catalog components. Each content item in the grid is a complex component named ContentItem.js that is repeated ...

Styling Mapbox GL JS markers on the fly with React

In my React (Next.js) project, I am utilizing mapbox-gl-js to work with maps. However, I am facing a challenge in dynamically styling markers differently when they are clicked. Specifically, I aim to enlarge the active marker and bring it to the forefront. ...

The TypeScript factory design pattern is throwing an error stating that the property does not

While working with TypeScript, I encountered an issue when trying to implement the factory pattern. Specifically, I am unable to access child functions that do not exist in the super class without encountering a compiler error. Here is the structure of my ...

Using a Class Decorator in Typescript to Enhance Static Methods across all Classes

Imagine having a class filled with numerous static methods. The objective is to encapsulate each static method within a function. The specific aim is to handle async errors by applying .catch to every static method in the following manner: // Within user-r ...

What is the best way to implement an Angular Guard that utilizes an API service for validation and redirects in case of failure?

Hello there! I am currently working on an Angular 7 application that deals with time cards. One of the main features I have implemented is a CanActivate Guard for controlling access to certain components. The CanActivate code utilizes Observables to decid ...

Error: Module not found - The package path "." is not exported from the specified package. As a result, Firebase will not update in your Next.js

I have been developing a Next.js application that retrieves data from a Firebase collection. During the process of connecting to the Firebase database, I have come across the following error: Failed to compile. Module not found This error seems to be ori ...

Having trouble with updating a Firebase database object using snap.val()

I'm trying to figure out how to update a property within the snap.val() in order to make changes to my Firebase database. function updateListItem(listItem) { var dbRef = firebase.database() .ref() .child('userdb') .child($sco ...

DiscordJS bot using Typescript experiences audio playback issues that halt after a short period of time

I am currently experiencing difficulties with playing audio through a discord bot that I created. The bot is designed to download a song from YouTube using ytdl-core and then play it, but for some reason, the song stops after a few seconds of playing. Bel ...

Tips for dynamically expanding the interface or type of an object in TypeScript

Currently, I am exploring the integration of PayPal's Glamorous CSS-in-JS library into a boilerplate project that also utilizes TypeScript. Glamorous provides a way to incorporate props into an element as shown below: const Section = glamorous.secti ...

Tips for incorporating auth0 into a vue application with typescript

Being a beginner in TypeScript, I've successfully integrated Auth0 with JavaScript thanks to their provided sample code. However, I'm struggling to find any sample applications for using Vue with TypeScript. Any recommendations or resources would ...

Error message: Nextjs encounters hydration issue only in the production environment

I've been facing this issue for hours now. I deployed my Next.js application on Vercel and encountered numerous hydration errors there. Interestingly, in my local development environment, I don't experience any errors at all. I came across sugge ...

A TypeScript function designed to only process arrays consisting of objects that contain a specific property determined by another parameter, with the requirement that this property

function retrieveObjectRow<T = string>( arrayData: { [key: T]: number; [key: string]: unknown; }[], targetValue: number, specifiedField: T ): typeof arrayData[number] | null { for (let i = 0; i < arrayData.lengt ...

Automatic type inference for functions in TypeScript with arguments

I am looking to define an interface with the following structure: interface CheckNActSetup<D, C> { defs: (event: Event) => D, context: (defs: D) => C; exec: (context: C) => any[]; when: ((context: C) => boolean)[]; } and implement it usi ...

Refreshing the page in Next.js results in the state being reset

My Next.js application features dynamic pages with URLs like products/[category]/[subcategory]. These pages all utilize the same component called ProductsList, which includes sorting functionality. I manage the state for sortingWay within this component to ...

Building an Event Scheduler in Outlook Calendar with Angular 5

Currently, I am utilizing Angular version 5.2 for a room booking portal project. One of the requirements entails adding an event to the Outlook calendar on the day a room is booked. The system includes a table listing all bookings, with a button in each ro ...

Troubleshooting Issue: Inability to apply border colors using Tailwind CSS on a

Trying to figure out tailwindcss and I've hit a roadblock. Experimented with different utility classes, all good. But now struggling with border-color. <div className="px-4 border-gray-900 border-solid"> <a href="#" className="block font- ...