nextjs-auth0: Module not found: Can't resolve 'v8' when using custom initAuth0

Checklist

  • The issue can be reproduced in the sample app (or N/A).
  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the examples and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

When using monorepos (with turbo and pnpm) and using an initAuth0 instance in a workspace project, we get a Module not found: Can't resolve 'v8' when using custom initAuth0 on all pages that try to call a nextjs api endpoint that uses getSession.

To explain the flow we are trying to achieve in our app:

  1. Client navigates to the app, and logs in using Auth0 credentials
  2. Cookie is set, and the custom profile handler adds some props to the userprofile object
  3. Client makes a call to a nextjs api endpoint, using the cookie as authentication
  4. The nextjs api endpoint calls another api, converting the cookie to an Authorization header before sending the request

Reproduction

See repo at https://github.com/azzlack/auth0-nextjs-initauth0-bug

NOTE: You need to populate the empty variables in the .env file

Run pnpm dev in the main branch to see a working version. Run pnpm dev in the monorepo branch to see a failing version.

SDK version

2.0.1

Next.js version

13.0.6

Node.js version

18

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

No worries @azzlack

Thanks for offering to add some docs about Turborepo, if it’s ok with you I’m going to hold off on documenting this until I know a little more about it. I suspect that it’s an issue in Turborepo, or turbopack - if I can create a minimal case I might go and raise an issue over there.

Hi @azzlack - Module not found: Can't resolve 'v8' means that you’re trying to bundle server-side only code into a client bundle.

The error is coming from here: https://github.com/azzlack/auth0-nextjs-initauth0-bug/blob/monorepo/apps/frontend/pages/index.tsx#L2 - where you’re importing a server component and a client component from the same target.

I noticed that if I split this import into 2 it works:

import { Auth0 } from "lib/src/Auth0";
import CatFactService from "lib/src/CatFactService";

If I had to guess I would say that Next.js’s default bundler is handling this case and splitting out the 2 imports as client and server imports. But the turborepo bundler isn’t.

This seems like an issue with turborepo or possibly turbopack (does turborepo use turbopack under the hood?) - I don’t think there’s much we can do on the SDK side unfortunately.