bug: Unable to use on NextJS v12.1.6 middleware with Edge Runtime
See original GitHub issueBug report
I recently tried updating to NextJS v12.1.6 and noticed that @supabase/supabase-js can no longer be used in Edge Functions. This is because native NodeJS APIs are not supported and it appears there are some dependencies of realtime-js that use these. Here is a look at the stack trace.
To Reproduce
Upgrade to NextJS 12.1.6 and try to use @supabase/supabase-js lib within a middleware function.
Additional context
Module not found: Can't resolve 'fs'
Import trace for requested module:
./node_modules/bufferutil/index.js
./node_modules/websocket/lib/WebSocketFrame.js
./node_modules/websocket/lib/websocket.js
./node_modules/websocket/index.js
./node_modules/@supabase/realtime-js/dist/module/RealtimeClient.js
./node_modules/@supabase/realtime-js/dist/module/index.js
./node_modules/@supabase/supabase-js/dist/module/index.js
./pages/api/v0/_middleware.ts
https://nextjs.org/docs/messages/module-not-found
You're using a Node.js module (fs) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Edge Runtime - Next.js
The Next.js Edge Runtime is based on standard Web APIs, which is used by Middleware and Edge API Routes. Network APIs.
Read more >Changelog - Cypress Documentation
Fixed a bug where projects using Node.js 16.17+ and 18.6+ with ES Modules and TypeScript were not working with Cypress. Fixes #22795, #23393,...
Read more >custom document next js Code Example - Code Grepper
import { Html, Head, Main, NextScript } from 'next/document' export default function Document() { return ( ) }
Read more >Using Next.js' middleware and Edge Functions - LogRocket Blog
Middleware is a Next.js feature that solves basic problems like authentication and geolocation with the help of Vercel Edge Functions.
Read more >May, 2022 - DefendEdge SiON
A remote, unauthenticated attacker could exploit this vulnerability to take control of an affected system. Microsoft has reported active exploitation of this ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This should be resolved as of
next@12.2.1
😃The fix is still being discussed. For Edge API route, I recommend you to switch back to regular routes, as @soedirgo suggested. Fixing them may require a bit more time than fixing the middleware.