Closed4

Supabaseで「Failed to load configuration: required key API_EXTERNAL_URL missing value」

RyukiRyuki

前提

Next.js 14でSupabase Authを使用すると「AuthApiError: PKCE flow is not ...」でgotrue-versionをv2.92.1に変更している。

Supabase STUDIOを使用してスキーマーを作成し、npx supabase db diff -f new_employeeを実行

% npx supabase db diff -f new_employee --local
Connecting to local database...
Creating shadow database...
Setting up initial schema...
{"level":"fatal","msg":"Failed to load configuration: required key API_EXTERNAL_URL missing value","time":"2023-10-31T15:18:56Z"}

SupabaseのProjectはリンクしていない。ローカルで開発を行っている。

RyukiRyuki

gotrue-versionのファイルを削除してSupabaseのDockerを再起動すると、migrationファイルの生成が成功したので、gotrue-versionが問題と推測

--use-migraは付けても付けなくても失敗していたので関係ないオプションと推測

supabase % npx supabase db diff -f new_employee --local --use-migra
Connecting to local database...
Creating shadow database...
Setting up initial schema...
Diffing schemas: extensions,public
Finished supabase db diff on branch main.
RyukiRyuki

Dockerイメージを確認

gotrue-versionを指定していないとpublic.ecr.aws/supabase/gotrue:v2.82.4を使用している。
npx supabase initの場合、古いgotrueが使用される?
!
public.ecr.aws/supabase/gotrue:v2.82.4

supabase/cliのコードを確認

2.9.2 introduced a bug
によると、gotrueの2.9.2からAPI_EXTERNAL_URL が必須に変わったらしい。

For anyone else hitting this error before we get a fix out, look for supabase/.temp directory and you should see a gotrue-version file. If your supabase start is already running you will need to run supabase stop first and then edit the gotrue-version file and set the version to 2.84.2 for now, then run supabase start again and all the other commands should be working again.

対応策はv2.82.4をインストールすることらしい。積みじゃん。

RyukiRyuki

supabase/cliのIssueを見てると、問題箇所はFIXされていた。
怪しいので、npx supabase ~~~のバージョンを確認

% npx supabase --version
1.86.1

(supabase - npm)(https://www.npmjs.com/package/supabase)
cliの最新は1.110.1

npmとnpxについて調べる

ChatGPTに確認

npmとnpxは、Node.jsのエコシステム内で異なる役割を果たすツールであり、それぞれが異なるバージョンを持つことがあります。以下の要因が、npmとnpxで実行する場合のバージョンの違いを生む可能性があります。
異なるパッケージのバージョン: npmはNode.jsのパッケージマネージャーであり、npxはパッケージ実行ツールです。これらのツールは、異なるパッケージやバージョンを対象とすることがあります。例えば、npmでインストールされたパッケージのバージョンと、npxで実行されたパッケージのバージョンが異なる可能性があります。
グローバルとローカルのインストール: npmは通常、グローバルまたはローカルにパッケージをインストールします。しかし、npxは通常、ローカルにインストールされたパッケージを実行し、それが見つからない場合には、一時的にパッケージをダウンロードして実行します。これにより、実行されるバージョンが異なる可能性があります。

npxは通常、ローカルにインストールされたパッケージを実行し、それが見つからない場合には、一時的にパッケージをダウンロードして実行します。

ローカルで1.86.1があるか確認

% npm list
/Users/user
├── @supabase/supabase-js@2.32.0
├── supabase@1.86.1
└── vercel@32.1.0

supabaseのcliが古いのでアップデート

% sudo npm i supabase --save-dev
Password:

added 2 packages, changed 2 packages, and audited 211 packages in 8s

17 packages are looking for funding
  run `npm fund` for details

8 vulnerabilities (4 low, 4 moderate)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

Supabaseのcliが新しいか確認

% npx supabase --version
1.110.1

Supabase Startを実行してgotrueのバージョンを確認

public.ecr.aws/supabase/gotrue:v2.99.0が使用されていた。

npx supabase db diff -f new_employeeが実行できるか確認

% npx supabase db diff -f new_employee --local
Unknown config fields: [auth.email.email_confirmations]
Unknown config fields: [auth.email.email_confirmations]
Connecting to local database...
Creating shadow database...
Setting up initial schema...
Diffing schemas: extensions,public
Finished supabase db diff on branch main.

問題なくmigrationsファイルが生成された。

# https://github.com/supabase/auth-helpers/issues/569
email_confirmations = true

は必要がないらしい。

サインアップができるか確認

localhost:3000/loginでサインアップができるか確認。
問題なくアカウント作成できた

このスクラップは6ヶ月前にクローズされました