5
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 のビルド時に Error: Cannot find module '/vercel/path0/node_modules/.pnpm/bcrypt エラーが出たときの対処法

Last updated at Posted at 2025-03-14

Next.js のビルド時に「Error: Cannot find module '/vercel/path0/node_modules/.pnpm/bcrypt」エラーが出たときの対処法です。

Next.js の公式チュートリアル Chapter 6 を進めていくと、Vercel のデプロイでこのエラーが出てしまいます。

チュートリアルをちゃんと読むと書いてあるのですが、分かりづらかったので忘備録として残しておきます。

The script uses bcrypt to hash the user's password, if bcrypt isn't compatible with your environment, you can update the script to use bcryptjs instead.

[DeepL翻訳]
スクリプトはbcryptを使用してユーザーのパスワードをハッシュしています。bcryptがあなたの環境と互換性がない場合は、代わりにbcryptjsを使用するようにスクリプトを更新することができます。

ビルドコマンド

pnpm run build

エラーメッセージ

[Error: Cannot find module '/vercel/path0/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node'
Require stack:
- /vercel/path0/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
- /vercel/path0/.next/server/app/seed/route.js
- /vercel/path0/node_modules/.pnpm/next@15.1.6_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/server/require.js
- /vercel/path0/node_modules/.pnpm/next@15.1.6_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/server/load-components.js
- /vercel/path0/node_modules/.pnpm/next@15.1.6_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/build/utils.js
- /vercel/path0/node_modules/.pnpm/next@15.1.6_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/build/worker.js
- /vercel/path0/node_modules/.pnpm/next@15.1.6_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/compiled/jest-worker/processChild.js] {
  code: 'MODULE_NOT_FOUND',
  requireStack: [Array]
}
> Build error occurred
[Error: Failed to collect page data for /seed] { type: 'Error' }
 ELIFECYCLE  Command failed with exit code 1.
Error: Command "pnpm run build" exited with 1

修正箇所

app/seed/route.ts

-import bcrypt from 'bcrypt';
+import bcrypt from 'bcryptjs';

package.json

-"bcrypt": "^5.1.1",
+"bcryptjs": "^3.0.2",
5
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
5
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?