Vue - 執行 NPM run npm 時出現 Supabase 錯誤
P粉121081658
P粉121081658 2024-03-27 14:38:27
0
1
324

所以我正在開發一個 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粉121081658
P粉121081658

全部回覆(1)
P粉129731808

將 .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);
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!