#nuxt project giving 500: "main.createClient is not a function" error

1 messages · Page 1 of 1 (latest)

void pawn
#

I am getting a 500 error after I call a Nuxt API deployed to vercel:

From this code:

import { createClient } from '@supabase/supabase-js'

export default defineEventHandler( async (event) => {
 const runtimeConfig = useRuntimeConfig()
 const supabase = createClient(runtimeConfig.supabase_url, runtimeConfig.supabase_service_role)
 return "nope"
})
// Simplified

And for whatever reason it works in dev but not when I deploy to production (vercel) suprised
The code lives in the /server/api folder of the nuxt repo and has the following package.json:

{
 "name": "kalt",
 "version": "4.2.0",
 "private": true,
 "scripts": {
   "build": "nuxt build",
   "dev": "nuxt dev",
   "generate": "nuxt generate",
   "preview": "nuxt preview"
 },
 "devDependencies": {
   "@nuxt/content": "^2.3.0",
   "@nuxtjs/supabase": "^0.3.0"
 },
 "dependencies": {
   "@nuxtjs/dotenv": "^1.4.1",
   "@supabase/supabase-js": "^2.2.3",
   "chart.js": "^4.1.1",
   "nuxt": "^3.0.0",
   "uuid": "^9.0.0",
   "vue-chartjs": "^5.1.0"
 }
}
novel fulcrum
#

Hey there, you need to make sure to implement supabase the right way. You’re currently installed it twice. You need to use the special server composables, and you can safely uninstall the @lofty smeltpabase/supabase-js.

I suggest you follow the docs for the supabase module step by step

Setup:
https://supabase.nuxtjs.org/get-started

Server: https://supabase.nuxtjs.org/usage/services/server-supabase-client

And then let us know if you still need helpX

Nuxt Supabase

@nuxtjs/supabase is a Nuxt module for first class integration with Supabase.

Nuxt Supabase

Supabase integration for Nuxt.

#

And also a tip, nuxt converts runtime config in camel case, so SUPABASE_URL would become runtimeConfig.supabaseUrl,

void pawn
#

Got it working after a few attempts 🙂 Super simple fix, thank you!

void pawn
#

Thank you very much for the help, really made my weekend a whole lot better 😄