supabase/supabase-js

Dynamic require of "stream" is not supported

Closed this issue · 5 comments

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Hello,

I am developing an application with Express and I am using Esbuild to compile it. Also, for a compatibility issue with certain libraries, the application is built and compiled in ESM mode.

However, after implementing the Supabase library, when I start the application I get this error:

Error: Dynamic require of “stream” is not supported

Inspecting the generated code, I see that it comes from @supabase/node-fetch.

var require_lib2 = __commonJS({
  "node_modules/@supabase/node-fetch/lib/index.js"(exports, module) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function _interopDefault(ex) {
      return ex && typeof ex === "object" && "default" in ex ? ex["default"] : ex;
    }
    var Stream = _interopDefault(__require("stream"));

Is there any way to not use that library or to be able to start it in ESM mode?

To Reproduce

Create a Node application (v22) and compile it with Esbuild in ESM mode.

I am also having this issue after upgrading my project to use ESM.

Is there a workaround available until this issue is fixed?

Check this out supabase/ssr#111. Basically you need to add additional config in your wranfler.jsonc file.

{
    ...,
    "compatibility_flags": [
       "nodejs_compat"
    ]
}

Hi, wonder if anyone has a fix for this?

I got it working with the following setup. Im not an expert so take it with a grain of salt.

esbuild.js:

import * as esbuild from 'esbuild';

await esbuild.build({
  entryPoints: ['src/index.ts'],
  bundle: true,
  outfile: 'dist/index.js',
  format: 'esm',
  platform: 'node',
  external: ['@supabase/node-fetch'],
  banner: {
    js: `
    import { createRequire } from 'module';
    const require = createRequire(import.meta.url);
  `
  }
});

Then you need to manually include @supabase/node-fetch in your deps.

npm i @supabase/node-fetch

We have removed node-fetch from the code. Ref: #1830

I am marking this issue as closed. If you find that the issue persists, tag me and I will reopen. Please try again with latest version!

Thank you all for your contribution!