Skip to content

Build Failure: bcrypt Module Not Found During Production Build #1034

Open
@ibrahimkonuk

Description

@ibrahimkonuk

Hi Team,

I'm encountering a build failure while following the Next.js dashboard tutorial (https://nextjs.org/learn/dashboard-app/getting-started). The issue occurs during the production build process (pnpm build).

Description of the Issue

The build process fails with a "Module Not Found" error related to the bcrypt package. Specifically, the error message indicates that the native bindings for bcrypt cannot be located.

nextjs-dashboard % pnpm build
> @ build /Users/.../nextjs-dashboard
> next build

   ▲ Next.js 15.1.6

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
   Collecting page data  ..[Error: Cannot find module '.../nextjs-dashboard/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node'
Require stack:
- .../nextjs-dashboard/node_modules/.pnpm/bcrypt@5.1.1/node_modules/bcrypt/bcrypt.js
- .../nextjs-dashboard/.next/server/app/seed/route.js
- .../nextjs-dashboard/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
- .../nextjs-dashboard/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
- .../nextjs-dashboard/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
- .../nextjs-dashboard/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
- .../nextjs-dashboard/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.

Context

This issue occurs during the pnpm build command, specifically when Next.js is attempting to collect page data. The error prevents a production build from being created.

Environment

  • Next.js version: 15.1.6 (as per the tutorial)
  • pnpm version: 10.6.5
  • Node.js version: v20.18.0
  • Package Manager: pnpm

Additional Information

During pnpm install, the following warning was also displayed:

Warning
Ignored build scripts: bcrypt, sharp.
Run "pnpm approve-builds" to pick which dependencies should
be allowed to run scripts.

Possible Root Cause

The bcrypt package relies on native bindings, which may not be correctly compiled or located during the build process, especially in a Next.js environment. The warning about ignored build scripts could be related.

Suggested Solution/Workaround

A workaround that resolves the issue is to replace bcrypt with bcryptjs. bcryptjs is a pure JavaScript implementation and does not require native bindings.

pnpm remove bcrypt
pnpm add bcryptjs

Impact

This build failure prevents users from completing the Next.js dashboard tutorial and deploying a production-ready application.

Thank you for your attention to this matter. I hope this information is helpful in resolving the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions