1

Using npm I have installed Nuxt 3 and Supabase but in vs code I keep getting the following error;

Cannot find name 'useSupabaseClient'.

When I run npm run dev I get the following error message on the page in the browser;

500 
useSupabaseClient is not defined

at _sfc_main.setup (C:\Users\User\Desktop\New folder (3)\supabase_nuxt\app.js:32:23)
at callWithErrorHandling (C:\Users\User\Desktop\New folder (3)\supabase_nuxt\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:193:18)
at setupStatefulComponent (C:\Users\User\Desktop\New folder (3)\supabase_nuxt\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:7538:25)
at setupComponent (C:\Users\User\Desktop\New folder (3)\supabase_nuxt\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:7499:36)
at renderComponentVNode (C:\Users\User\Desktop\New folder (3)\supabase_nuxt\node_modules\@vue\server-renderer\dist\server-renderer.cjs.js:642:15)
at Module.ssrRenderComponent (C:\Users\User\Desktop\New folder (3)\supabase_nuxt\node_modules\@vue\server-renderer\dist\server-renderer.cjs.js:91:10)
at default (C:\Users\User\Desktop\New folder (3)\supabase_nuxt\node_modules\nuxt\dist\app\components\nuxt-root.js:76:37)
at Module.ssrRenderSuspense (C:\Users\User\Desktop\New folder (3)\supabase_nuxt\node_modules\@vue\server-renderer\dist\server-renderer.cjs.js:489:5)
at _sfc_ssrRender (C:\Users\User\Desktop\New folder (3)\supabase_nuxt\node_modules\nuxt\dist\app\components\nuxt-root.js:67:25)

What is causing this issue?

Below is some additional information.

package.json

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "devDependencies": {
    "@nuxtjs/supabase": "^1.1.5",
    "nuxt": "^3.9.0",
    "vue": "^3.4.6",
    "vue-router": "^4.2.5"
  }
}

nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },
  modules: ['@nuxtjs/supabase'],
});

My .env file has the correct Supabase credentials

.env

SUPABASE_URL="https://example.supabase.co"
SUPABASE_KEY="<your_key>"

app.vue

<template>
  <div>
    <NuxtWelcome />
  </div>
</template>
<script setup lang="ts">
const client = useSupabaseClient()
</script>

I did the following;

  1. Made sure that the Supabase credentials (like the Supabase key and url) in the .env are correct. 2``Updated node to the current version which is 20.11.0.
  2. Verified that the Supabase client is installed by using the npm list @supabase/supabase-js command. It showed the following;
@nuxtjs/[email protected]
  └── @supabase/[email protected]

4.Restarting the development server.

2 Answers 2

1

I ran into a similar issue.

The problem went away after removing typescript from script setup:

<script setup lang="ts">
const supabase = useSupabaseClient();

To:

<script setup>
const supabase = useSupabaseClient();

While trying to understand the issue better so I could post an informed answer, I added lang="ts" back, and everything continued to work. My guess is that the components did not wire correctly the first time.

Sign up to request clarification or add additional context in comments.

Comments

0

I try to reinstall the dependencies with:

npm install

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.