0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Nextjsをvercelに上げたらでたエラーその2: is assigned a value but never used

Posted at

この記事ではNextjsでvercelに上げたらでたエラーについて書いています。

エラー内容

Failed to compile.
./src/app/page.tsx
9:17  Error: 'session' is assigned a value but never used.  @typescript-eslint/no-unused-vars
info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/app/api-reference/config/eslint#disabling-rules
Error: Command "npm run build" exited with 1

エラー理由

このエラーは、sessionが変数として定義されているにも関わらず、その値がコード内で使用されていないために発生しています。ESLintの@typescript-eslint/no-unused-varsルールが、未使用の変数を警告しています。

エラーが発生した行を見ると、sessionが宣言されているけれども実際に利用されていない状態です。

エラー解決方法

sessionを使用する

const { data: session, status } = useSession();

if (session) {
  console.log(session.user.name); // sessionの情報を使う例
}

sessionの宣言を削除

const { status } = useSession(); // sessionを削除

強引な方法

ESLintルールを無効化(警告を無視)したい場合、@typescript-eslint/no-unused-varsルールを無効化することもできます。next.config.jsに以下を追加して、ビルド時の警告を無視できます

module.exports = {
  eslint: {
    ignoreDuringBuilds: true,
  },
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?