首頁  >  問答  >  主體

Vue - 執行 NPM run npm 時出現 Supabase 錯誤

所以我正在開發一個 Vue 應用程式。後來我想使用 Supabase 新增一個後端並部署到 Vercel。但是,在我向其中添加後端元素後,當我執行 npm runserve 時,它會拋出以下錯誤:

ERROR  Failed to compile with 1 error                                                                                                                                                                                            1:31:54 PM

 error  in ./src/supabase.js

Module parse failed: Unexpected token (2:24)
File was processed with these loaders:
 * ./node_modules/cache-loader/dist/cjs.js
 * ./node_modules/babel-loader/lib/index.js
 * ./node_modules/eslint-loader/index.js
You may need an additional loader to handle the result of these loaders.
| import { createClient } from "@supabase/supabase-js";
> var supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
| var supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
| export var supabase = createClient(supabaseUrl, supabaseAnonKey);

有人知道這是什麼意思嗎?我有另一個透過 Vite 設定的 Vue 應用程序,它在本地運行良好,但在這個不是由 Vite 設定的 Vue 應用程式中運行不佳。

P粉121081658P粉121081658205 天前317

全部回覆(1)我來回復

  • P粉129731808

    P粉1297318082024-03-28 09:42:42

    將 .env 變數從 VITE_SUPABASE_URL 改為 VUE_APP_SUPABASE_URL,並將 import.meta.env 改為 process.env。

    範例:

    從此

    import { createClient } from '@supabase/supabase-js'
    
    const supabaseUrl = import.meta.env.VITE_SUPABASE_URL
    const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY
    
    export const supabase = createClient(supabaseUrl, supabaseAnonKey)

    至此

    import { createClient } from "@supabase/supabase-js";
    
    const supabaseUrl = process.env.VUE_APP_SUPABASE_URL;
    const supabaseAnonKey = process.env.VUE_APP_SUPABASE_ANON_KEY;
    
    export const supabase = createClient(supabaseUrl, supabaseAnonKey);

    回覆
    0
  • 取消回覆