vercel에 연동된 Next.js프로젝트에 postgres를 연동하던중 아래와 같은 오류가 발생하였다.
Error while fetching side menu data: VercelPostgresError: VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found.
오류상으로는 'connectionString', 'POSTGRES_URL'에 대해서만 나와서 다른 문제라고는 생각하지 못했는데
생각보다 간단한 문제로 나던 오류였다.
💊 해결 방법
postgres 데이터를 직접 불러오는 파일이 클라이언트 컴포넌트 상태라서 생기는 문제였다.
'use server'를 파일 상단에 입력하여 서버 컴포넌트로 변경시키는 것으로 간단하게 해결되었다.
'use server'
import { sql } from "@vercel/postgres";
interface MenuItem {
id: number;
name: string;
description: string;
link: string;
sub_menus: SubMenuItem[];
}
interface SubMenuItem {
id: number;
name: string;
description: string;
link: string;
}
export async function getSideMenuData(): Promise<MenuItem[]> {
try {
const { rows }: { rows: MenuItem[] } = await sql`SELECT
m.id AS id,
m.name AS name,
m.description AS description,
m.link AS link,
COALESCE(json_agg(json_build_object('id', sub.id, 'name', sub.name, 'description', sub.description, 'link', sub.link)) FILTER (WHERE sub.id IS NOT NULL), '[]') AS sub_menus
FROM
side_menu AS m
LEFT JOIN
side_menu AS sub ON m.id = sub.parent_id
WHERE
m.parent_id IS NULL
GROUP BY
m.id;
`;
return rows;
} catch (error) {
throw new Error('Failed to fetch side menu data');
}
}
VS Code는 자체적으로 최신 버전의 TypeScript가 기본으로 제공되는데, 이는 작업 파일을 컴파일하는 데 사용하는 TypeScript 버전과 별개이다. 일반적으로는 VS Code에서 기본으로 제공하는 TypeScript 버전을 사용할 수 있지만 문제가 생기면 작업 파일 버전으로 변경해야 할 수도 있다. (변경 방법은 위에 설명드린 내용과 같습니다)
redux-toolkit을 사용하기 위해 라이브러리를 설치했는데 프로젝트 실행시 아래와 같은 오류가 발생하였다.
./node_modules/@reduxjs/toolkit/dist/redux-toolkit.legacy-esm.js
SyntaxError: /Users/otdeal/Desktop/projects/otdeal_projects/robomd/frontend/node_modules/@reduxjs/toolkit/dist/redux-toolkit.legacy-esm.js: Missing class properties transform.
여러가지 라이브러리를 설치하면서 꼬이거나 오류가 발생했을까 싶어서,
node_modules를 지우고 package.json의 모듈을 다시 설치해주기 위해 'yarn' 명령어를 실행했는데 아래와 같은 오류가 발생했다.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
error expect@29.7.0: The engine "node" is incompatible with this module. Expected version "^14.15.0 || ^16.10.0 || >=18.0.0". Got "16.8.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
에러 메세지를 확인하니 node 버전 문제로 인해 발생하는 오류로 확인되었다.
현재 사용하고 있던 노드 버전이 많이 낮은 상태였기 때문에 과감하게 노드 버전을 LTS 버전으로 변경하기로 하였다.
yarn 버전 업그레이드를 할 일이 생겨서 'brew upgrade yarn' 명령어를 실행했는데 오류가 발생하였다.
Error:
homebrew-cask is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
This command may take a few minutes to run due to the large size of the repository.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
에러 메세지에 'brew update'를 실행하기 위해서 어떤 명령어를 입력해야하는지 친절하게 알려주고있다.