Building NextJS with Typescript encountered an error while using @auth0/nextjs-auth0

I am currently facing an issue while trying to build my NextJS application using Typescript. The problem lies with the auth0/nextjs-auth0 package, causing persistent errors during installation.

One specific error can be found at the following link: https://i.sstatic.net/L7sB7.jpg

Sharing my tsconfig.json file for reference:

    {
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "lib": [
      "es6",
      "es7",
      "esnext",
      "dom"
    ],
    "allowJs": true,
    // "checkJs": true,
    "jsx": "preserve",
    "removeComments": false,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "moduleResolution": "node",
    "baseUrl": ".",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "inlineSourceMap": true,
    "inlineSources": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "declaration": true,
    "declarationDir": "./node_modules/@auth0/nextjs-auth0/src/auth0-session",
    "declarationMap": true
  },
  "include": [
    "pages"
  ],
  "exclude": [
    "node_modules"
  ]
}

Answer №1

Attempt to resolve the issue as indicated by executing:

npm install --save-dev @types/url-join

If the above command does not solve the problem, you can attempt removing the node_modules directory and then proceed with running npm install or yarn

Answer №2

If you're facing issues with auth0 integration, I suggest checking out the official example for guidance. I encountered similar challenges when using auth0 embed. Remember to ensure that you include your <Component> in the app.js file to enable auth0 functionality on pages and utilize withAuthRequired

import { UserProvider } from '@auth0/nextjs-auth0';

export default function App({ Component, pageProps }) {
  const { user } = pageProps;
  return (
      <UserProvider user={user}>
        <Component {...pageProps} />
      </UserProvider>
  );
}

Answer №3

Make sure to review your "tsconfig.json" configuration file for the compilation option called "exclude". If this option is missing, simply insert it and specify that you want to exclude the "node_modules" directory.

// tsconfig.json
{
  "compilerOptions": {
  ...
  "exclude": [
    "node_modules", 
  ]
}

Answer №4

To fix the issue, try removing the node_modules and package-lock.json files, then run npm install. If the problem persists, consider using this specific version:

"@auth0/nextjs-auth0": "^1.2.0",

I have successfully implemented this package on my portfolio website without encountering any problems. The issue could potentially be a bug in the latest version.

Answer №5

Perhaps this solution could benefit others facing a similar issue. In my experience, the problem stemmed from an incorrect import (autocomplete) that was directing the Session from the src directory.

import { Session } from '@auth0/nextjs-auth0/src/session';

Answer №6

Consider trying the next authentication approach for a smoother experience. Configure your provider in your Server.js file.

import NextAuth from 'next-auth'
import AppleProvider from 'next-auth/providers/apple'
import FacebookProvider from 'next-auth/providers/facebook'
import GoogleProvider from 'next-auth/providers/google'
import EmailProvider from 'next-auth/providers/email'

export default NextAuth({
  providers: [
    // OAuth authentication providers...
    AppleProvider({
      clientId: process.env.APPLE_ID,
      clientSecret: process.env.APPLE_SECRET
    }),
    FacebookProvider({
      clientId: process.env.FACEBOOK_ID,
      clientSecret: process.env.FACEBOOK_SECRET
    }),
    GoogleProvider({
      clientId: process.env.GOOGLE_ID,
      clientSecret: process.env.GOOGLE_SECRET
    }),
    // Passwordless / email sign in
    EmailProvider({
      server: process.env.MAIL_SERVER,
      from: 'NextAuth.js <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f79998da8592879b8eb7928f969a879b92d994989a">[email protected]</a>>'
    }),
  ]
})

Update App.js

import { SessionProvider } from "next-auth/react"

export default function App({
  Component, pageProps: { session, ...pageProps }
}) {
  return (
    <SessionProvider session={session}>
      <Component {...pageProps}/>
    </SessionProvider>
  )
}

Edit Index.js

import { useSession, signIn, signOut } from "next-auth/react"

export default function Component() {
  const { data: session } = useSession()
  if(session) {
    return <>
      Signed in as {session.user.email} <br/>
      <button onClick={() => signOut()}>Sign out</button>
    </>
  }
  return <>
    Not signed in <br/>
    <button onClick={() => signIn()}>Sign in</button>
  </>
}

Create a .env.local file and input your provider client ids and secrets.

Answer №7

After encountering a compile error while following the nextjs documentation on GitHub, I decided to delete the node modules and package.json files and run npm install. Surprisingly, switching the original import statement from the nextjs GitHub to:

import { useUser } from '@auth0/nextjs-auth0/client';

resolved the issue for me. I found this alternative import on the npm documentation page. https://www.npmjs.com/package/@auth0/nextjs-auth0

Hopefully, this solution works for you too!

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

Angular location services

I'm experiencing some difficulties with the geolocation feature. It works fine when the user clicks allow, but there's an issue when using If else. If the user clicks deny, it doesn't insert into the else block. You can check out this DEMO f ...

What is the method for accessing a validator that has been declared in a reactive form group while within the scope of a custom

Currently, I have a custom component that I am happy with and it is being used in a reactive form as shown below. private init() { const control4 = new FormControl("yy", Validators.pattern(".{2}")); const control5 = new FormControl("zz", Validators.pa ...

What is the best way to remove linear-gradient effects applied by a dark mode theme?

Why does MUI add random gradients to components, like in dark mode? Is there a way to disable this feature because it doesn't match the exact color I expected for my custom theme... My Theme Options export const themeOptions: ThemeOptions = { palette ...

I am encountering an issue where the props in NextJS consistently return as undefined

I am currently working on setting up a connection with Contentful. The connection itself seems to be functioning properly and is not the issue, however, when I attempt to transfer the data using props, I keep receiving 'undefined'. I have simpli ...

Alert: Potential shared module issue detected when updating swr from version 1 to version 2 within a NextJS application

I have decided to upgrade my swr package from version 1 to the latest version 2. Here is a glimpse of my package.json. I am currently utilizing React 18, NextJS 12, and Webpack 5 for this project, including the ModuleFederationPlugin integration. { " ...

Effortlessly adding custom classes in Angular 2 with a breeze

Imagine having a growing Angular2 typescript solution with numerous small classes and objects. Following the best practice, each class is placed in its own file. However, manipulating these objects leads to long lists of imports like: import {Object1} f ...

Issue with implementing MUI Style Tag in conjunction with styled-components and Typescript

I have created a custom SelectType component using Styled Components, which looks like this: import Select from '@mui/material/Select'; export const SelectType = styled(Select)` width:100%; border:2px solid #eaeaef; border-radius:8px ...

What is the reason for TS expressing dissatisfaction about the use of a type instead of a type entry being provided

Below is a snippet of code for a Vue3 component that takes in an Array of Objects as a prop: <script lang="ts"> interface CorveesI { What: string, Who: string, Debit: number } export default { name: 'Corvees', props: { ...

Developing maintenance logic in Angular to control subsequent API requests

In our Angular 9 application, we have various components, some of which have parent-child relationships while others are independent. We begin by making an initial API call that returns a true or false flag value. Depending on this value, we decide whether ...

retrieving necessary components from sdk_aws

When I updated my project, I encountered the following error while trying to execute the ng serve command: ERROR in node_modules/aws-sdk/clients/s3.d.ts(12,24): error TS2307: Cannot find module 'stream'. node_modules/aws-sdk/clients/s3.d.ts(908,2 ...

Exploring ways to conduct a thorough scan of object values, inclusive of nested arrays

My goal is to extract all values from an object. This object also includes arrays, and those arrays contain objects that in turn can have arrays. function iterate(obj) { Object.keys(obj).forEach(key => { console.log(`key: ${key}, value: ${o ...

Leverage the power of React, Material-UI, and Typescript to inherit button props and incorporate a variety of unique

Looking to enhance the Material-UI button with additional variants like "square." How can I create a prop interface to merge/inherit props? Check out the following code snippet: import React from "react"; import { Button as MuiButton } from "@material-u ...

Typescript is struggling to accurately infer extended types in some cases

My goal is to optimize the body of a NextApiRequest for TypeScript. I currently have this code snippet: // This is a type from a library I've imported export interface NextApiRequest { query: Partial<{ [key: string]: string | string[]; ...

Trouble accessing nested components in Angular CLI beyond the first level of components

I'm diving into Angular CLI for the first time and trying to recreate a previous web project of mine. I've managed to nest and display components inside the root component successfully, but after that, I'm facing issues referencing any compo ...

Is there a way for me to steer clear of having to rely on the Elvis Operator?

Throughout my journey building my Angular 2 website, I've found the Elvis Operator to be a crucial element that makes everything possible. It seems like every task I undertake involves mastering how to apply it correctly in every instance where data i ...

NextJS is like the master of ceremonies in the world of backend

As I was searching for the top JS backend frameworks, I came across NextJS which is considered to be one of the best. Initially, I thought NextJS was just a simplified version of CRA and still required Node.js as the backend. This brought me back to my c ...

The function parameter in Angular's ngModelChange behaves differently than $event

How can I pass a different parameter to the $event in the function? <div class='col-sm'> <label class="col-3 col-form-label">Origen</label> <div class="col-4"> <select ...

Having continual issues with OAuthCreateAccount error on Next.js with Next Auth using Google as the provider

I have successfully set up next-auth with the GoogleProvider on my local environment. However, when trying to run it in production, I encountered an OAuthCreateAccount error: api/auth/signin?error=OAuthCreateAccount The error message prompts me to "Try s ...

Encountered a glitch when utilizing the callbacks feature in Next-auth

I am currently working on integrating the custom session from Next-Auth to my client-side application. The route.js file in my app/api/auth/[...nextauth] directory looks like this: import { MongoClient } from "mongodb"; import CredentialsProvider ...

Displaying images in ReactJS, NextJS, or Tailwind UI may not be straightforward

I am facing an issue with changing the image sourced from "https://tailwindui.com/img/logos/workflow-mark.svg?color=indigo&shade=600". Every time I try to replace it with a local image from my directory, only a default image appears. Does anyone have a ...