supabase / storage-js

JS Client library to interact with Supabase Storage
Apache License 2.0
127 stars 37 forks source link

Getting `A spread argument must either have a tuple type or be passed to a rest parameter.` on supabase storage when deploying Vite app to vercel #192

Closed eRuaro closed 8 months ago

eRuaro commented 8 months ago

Bug report

Describe the bug

I'm getting this error when deploying my application to Vercel

node_modules/@supabase/storage-js/src/lib/helpers.ts(13,30): error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter.
Error: Command "npm run build" exited with 2

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a React app using Vite, with the following tsconfig

    // tsconfig.json
    {
    "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "lib": [
      "ES2020",
      "DOM",
      "DOM.Iterable"
    ],
    "module": "ESNext",
    "skipLibCheck": true,
    "noImplicitAny": false,
    "incremental": true,
    "forceConsistentCasingInFileNames": true,
    "sourceMap": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    /* Linting */
    "strict": false,
    "useUnknownInCatchVariables": false,
    "strictPropertyInitialization": false,
    "allowJs": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noFallthroughCasesInSwitch": true,
    
    "types": [
      "vite/client"
    ]
    },
    "include": [
    "src",
    "index.d.ts",
    "src/**/*.ts",
    "src/**/*.spec.ts",
    "src/**/*.d.ts",
    ],
    "exclude": [
    "node_modules",
    ],
    "references": [
    {
      "path": "./tsconfig.node.json"
    }
    ]
    }
  2. Deploy to Vercel

Expected behavior

Build will run fine.

System information

Additional context

Editing the source code directly makes the build work on my localhost, here's the original code.

type Fetch = typeof fetch

export const resolveFetch = (customFetch?: Fetch): Fetch => {
  let _fetch: Fetch
  if (customFetch) {
    _fetch = customFetch
  } else if (typeof fetch === 'undefined') {
    _fetch = (...args) =>
      import('@supabase/node-fetch' as any).then(({ default: fetch }) => fetch(...args))
  } else {
    _fetch = fetch
  }
  return (...args) => _fetch(...args)
}

Here's the updated code:

type Fetch = typeof fetch

export const resolveFetch = (customFetch?: Fetch): Fetch => {
  let _fetch: Fetch
  if (customFetch) {
    _fetch = customFetch
  } else if (typeof fetch === 'undefined') {
    _fetch = (...args) =>
      import('@supabase/node-fetch' as any).then(({ default: fetch }) => fetch(...args))
  } else {
    _fetch = fetch
  }
  return (...args: Parameters<Fetch>) => _fetch(...args)
}
eRuaro commented 8 months ago

Fixed this by modifying my build command in my package.json to just vite build instead of tsc && vite build