question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Unable to use on NextJS v12.1.6 middleware with Edge Runtime

See original GitHub issue

Bug 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:closed
  • Created a year ago
  • Reactions:6
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
soedirgocommented, Jul 12, 2022

This should be resolved as of next@12.2.1 😃

3reactions
feugycommented, Jul 4, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found