搜索

首页  >  问答  >  正文

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粉121081658315 天前429

全部回复(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
  • 取消回复