Vercel Edge Nodes and expoSecureStore in NextJS SDK
I updated Vercel to Node 22 and now I can't deploy anymore. It seems that the NextJS Kinde SDK includes some Expo (react native?!) modules that are not supported.
Setting
runtime = 'nodejs'
in middleware.ts did not solve it.8 Replies
Claude suggests to rewrite
middleware.ts
to avoid importing withAuth
to:
I don't know if those cookie names are accurate or hallucinated.
This seems to trigger a redirection infinite loop.Hey @Tito, could you please let me know which version of
@kinde-oss/kinde-auth-nextjs
you’re using? "@kinde-oss/kinde-auth-nextjs": "^2.8.6",
i tried to upgrade to the latest, is it the latest?
I haven't set any route or page to edge
, so it looks like it's an issue with the vercel deploy process. I can build correctly, but it fails when running it. It seems that some Expo related dependency ended up in the kinde-auth-nextjs
package by mistake? I am not sure what triggered the problem for me, most likely I clicked on the "upgrade" request (from node 18 to node 20) on vercel
The problem is with @kinde/js-utils
that dynamically imports expo-local-storage
This is the dependency tree:
This is a total blocker, I am stuck. js-utils is cross platform, but Vercel can't deploy it
I've tried a number of tricks in next.config.js
to avoid bundling the expo-local-storage
package, but nothing worked. This is my config file:
i don't understand why i didn't have the problem, i always used next 14 in this project. The only thing that happened is upgrading to node 20 and 22.
I was on @kinde-oss/kinde-auth-nextjs 2.3.10
until today; when i encountered the issue I upgraded to the latest version 2.8.6
today, but that didn't solve it.Hey @Tito, thank you for all the detailed notes and the dependency tree, that’s really helpful. I’ll investigate this first thing tomorrow.
I really appreciate your patience here. Please feel free to share anything else you discover in the meantime - I’ll make sure to pick it up when I start.
By default middleware is always run on edge runtime. It's only recently in some Next 15.x version that they added an experimental flag to run middleware on nodejs runtime (which probably would bypass the issue; i have not tried). Maybe Node18 didn't check and given that expo is not actually used, it never triggered any error
Hey @Tito, I’ve just finished attempting to replicate the issue using Next 14, the same library versions you listed, with Node 22, and deployed it to Vercel. The deployment completed successfully without triggering the unsupported modules error.
You can review the reproduction here:
- GitHub repo: https://github.com/abdelrahman-zaki/kinde-nextjs-edge-repro
- Deployed Vercel URL: https://kinde-nextjs-edge-repro.vercel.app/
This should help as a baseline to compare against your project’s setup so we can pinpoint any differences that might be causing the failure on your side.
GitHub
GitHub - abdelrahman-zaki/kinde-nextjs-edge-repro
Contribute to abdelrahman-zaki/kinde-nextjs-edge-repro development by creating an account on GitHub.
Kinde Auth
Kinde with NextJS App Router
Thanks. I believe the fix was to upgrade Next from 14.1.x to 14.2.31 as the older version conflicted with Node 20
Got it, thanks for confirming. Good to hear upgrading to Next 14.2.31 fixed the issue.
Let me know if you run into any other issues.