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?

Next.jsとprismaでアプリを作ったとき、Vercelデプロイすると「Method Not Allowed」エラーが起きる

Posted at

はじめに

表題通りのエラーに遭遇しましたので簡単に書き残しておきます。

概要

Next.jsとprismaでアプリを作成し、Vercelでデプロイすると、apiにPOSTリクエストした際に"Method Not Allowed"エラーが生じる。このエラーはローカルでは生じない。

解決策

VercelのビルドページのLogに以下のようなログがあるのを発見

⨯ Error [PrismaClientInitializationError]: Prisma has detected that this project was built on Vercel, which caches dependencies. 
This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. To fix this, make sure to run the `prisma generate` command during the build process.

調べてみると、Vercelのデプロイ時にprisma generateができていなかったのが原因らしい。
package.jsonの"scripts"を以下のように書き換えることで解決した。

  "scripts": {
    "postinstall": "prisma generate",
    "build": "prisma generate && next build",
    "dev": "next dev",
    "start": "next start"
  },
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?