supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

Unused import warnings persist in dist/index.mjs despite #1979 fix

Open snake-poison opened this issue 1 month ago • 2 comments

Describe the bug

When using @supabase/supabase-js with Vite (or any Rollup-based bundler), the following warnings appear during build/dev:

WARN  "PostgrestError" is imported from external module "@supabase/postgrest-js" but never used in "@supabase/supabase-js/dist/index.mjs"

WARN  "FunctionRegion", "FunctionsError", "FunctionsFetchError", "FunctionsHttpError" and "FunctionsRelayError" are imported from external module "@supabase/functions-js" but never used in "@supabase/supabase-js/dist/index.mjs"

Previous Fix Attempt

PR #1979 correctly addressed this in the source TypeScript (src/index.ts) by using direct re-export syntax:

export { PostgrestError } from '@supabase/postgrest-js'
export { FunctionRegion, FunctionsError, ... } from '@supabase/functions-js'

However, the warnings persist because the build output (dist/index.mjs) doesn't preserve this pattern. The bundler transforms it into:

// Built output (line 1-2)
import { FunctionRegion, FunctionsClient, FunctionsError, ... } from "@supabase/functions-js";
import { PostgrestClient, PostgrestError } from "@supabase/postgrest-js";

// ... 400 lines later (line 405) ...
export { FunctionRegion, FunctionsError, ..., PostgrestError, SupabaseClient, createClient };

Rollup's tree-shaking analysis doesn't recognize that these imports are used solely for re-export, triggering the "imported but never used" warning.

Root Cause

The package uses tsdown for building (tsdown.config.ts), which transforms export { X } from "module" into separate import and export statements. The build configuration or tooling would need to preserve the original re-export syntax.

Environment

  • @supabase/supabase-js: 2.90.0
  • Bundler: Vite 6.x (Rollup-based)
  • Framework: Nuxt 4

Workaround

Manually patching dist/index.mjs (via pnpm patch) to use direct re-exports eliminates the warnings:

Before (current build output):

import { FunctionRegion, FunctionsClient, FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError } from "@supabase/functions-js";
import { PostgrestClient, PostgrestError } from "@supabase/postgrest-js";
// ... later ...
export { FunctionRegion, FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, PostgrestError, SupabaseClient, createClient };

After (working fix):

import { FunctionsClient } from "@supabase/functions-js";
import { PostgrestClient } from "@supabase/postgrest-js";
export { FunctionRegion, FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError } from "@supabase/functions-js";
export { PostgrestError } from "@supabase/postgrest-js";
// ... later ...
export { SupabaseClient, createClient };

Library affected

supabase-js

Reproduction

No response

Steps to reproduce

No response

System Info

System:
    OS: macOS 26.3
    CPU: (12) arm64 Apple M2 Max
    Memory: 2.81 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.9.0 - /Users/snake/.nvm/versions/node/v24.9.0/bin/node
    npm: 11.6.0 - /Users/snake/.nvm/versions/node/v24.9.0/bin/npm
    pnpm: 10.27.0 - /Users/snake/Library/pnpm/pnpm
  Browsers:
    Chrome: 143.0.7499.170
    Safari: 26.3
  npmPackages:
    @supabase/supabase-js: ~2.90.0 => 2.90.0

Used Package Manager

pnpm

Logs

No response

Validations

snake-poison avatar Jan 07 '26 20:01 snake-poison

@snake-poison thank you for reporting this. Can you please create a minimum reproduction repository, which I can use for my local testing?

mandarini avatar Jan 08 '26 12:01 mandarini

@snake-poison thank you for reporting this. Can you please create a minimum reproduction repository, which I can use for my local testing?

checkout https://github.com/snake-poison/supabase-js--2010-repro

pnpm install && pnpm build

observe the build logs message:

ℹ Building Nuxt Nitro server (preset: node-server, compatibility date: 2025-07-07)                                                                                                                             nitro 6:24:06 PM
"PostgrestError" is imported from external module "@supabase/postgrest-js" but never used in "node_modules/.pnpm/@[email protected]/node_modules/@supabase/supabase-js/dist/index.mjs".
"FunctionRegion", "FunctionsError", "FunctionsFetchError", "FunctionsHttpError" and "FunctionsRelayError" are imported from external module "@supabase/functions-js" but never used in "node_modules/.pnpm/@[email protected]/node_modules/@supabase/supabase-js/dist/index.mjs".
✔ Nuxt Nitro server built                                                                                                                                                                                      nitro 6:24:07 PM

snake-poison avatar Jan 11 '26 23:01 snake-poison

Yep getting this with Nuxt + Nuxt Supabase. I thought it was nuxt supabase library problem but I guess not? Don't know when I started getting these, I think probably after an update?

[3:40:25 PM]  WARN  "PostgrestError" is imported from external module "file://C:/CODING_STUFF/PROJECTS/YAPSAK/yapsak/node_modules/.pnpm/@[email protected]/node_modules/@supabase/postgrest-js/dist/index.mjs" but never used in "node_modules/.pnpm/@[email protected]/node_modules/@supabase/supabase-js/dist/index.mjs".


[3:40:25 PM]  WARN  "FunctionRegion", "FunctionsError", "FunctionsFetchError", "FunctionsHttpError" and "FunctionsRelayError" are imported from external module "file://C:/CODING_STUFF/PROJECTS/YAPSAK/yapsak/node_modules/.pnpm/@[email protected]/node_modules/@supabase/functions-js/dist/main/index.js" but never used in "node_modules/.pnpm/@[email protected]/node_modules/@supabase/supabase-js/dist/index.mjs".
 "dependencies": {
    "@block65/webcrypto-web-push": "^1.0.2",
    "@iconify-json/lucide": "^1.2.86",
    "@nuxt/image": "2.0.0",
    "@nuxt/scripts": "^0.12.2",
    "@nuxt/ui": "^4.3.0",
    "@nuxtjs/sitemap": "^7.5.2",
    "@nuxtjs/supabase": "2.0.3",
    "@nuxtjs/turnstile": "1.1.1",
    "@vite-pwa/nuxt": "1.1.0",
    "canvas-confetti": "^1.9.4",
    "nuxt": "^4.2.2",
    "nuxt-meilisearch": "1.4.17",
    "prismjs": "^1.30.0"
  },
  "devDependencies": {
    "@nuxt/eslint": "^1.12.1",
    "eslint": "^9.39.2",
    "typescript": "^5.9.3",
    "vue-tsc": "^3.2.2"
  },
  "packageManager": "[email protected]"

onurusluca avatar Jan 21 '26 06:01 onurusluca