nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
23.24k stars 3.18k forks source link

Package subpath './jwt' is not defined by "exports #8415

Closed coado closed 10 months ago

coado commented 10 months ago

Environment

System: OS: Linux 5.19 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish) CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor Memory: 20.28 GB / 31.27 GB Container: Yes Shell: 5.1.16 - /bin/bash Binaries: Node: 20.5.1 - /usr/local/bin/node Yarn: 3.4.1 - /usr/local/bin/yarn npm: 9.8.0 - /usr/local/bin/npm pnpm: 8.5.1 - /usr/local/bin/pnpm Browsers: Chrome: 112.0.5615.121

Reproduction URL

https://github.com/coado/jwt-decode-issue

Describe the issue

I have a NextJS app that uses NextAuth for authorization and authentication. I also have a separate server that handles websocket connections. I have to authenticate incoming connections based on the next-auth jwt token. What I am trying to do is to decode jwt token using decode function located in @auth/core/jwt https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/jwt.ts#L64-L74, but I get this error message when I try to use it: Package subpath './jwt' is not defined by "exports".

I have tried to use stable/latest node versions, updating all packages, removing and reinstalling node_modules.

How to reproduce

Clone the repo, install packages, and run the command: pnpm start.

Expected behavior

It shouldn't throw an error

rinvii commented 10 months ago

Import from next-auth instead.

pnpm add next-auth

...

import { decode } from "next-auth/jwt";
coado commented 10 months ago

It worked! Thank you so much!