# Cannot find module 'bcrypt' error in Function

**URL:** <https://answers.netlify.com/t/cannot-find-module-bcrypt-error-in-function/101808>\
**Category:** Support\
**Tags:** lambda-functions\
**Created:** [September 13, 2023, 4:29pm UTC](https://answers.netlify.com/t/cannot-find-module-bcrypt-error-in-function/101808 "2023-09-13T16:29:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rapanaki](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/rapanaki/32/54468_2.png) [@rapanaki](https://answers.netlify.com/u/rapanaki)\
**Post date:** [September 13, 2023, 4:29pm UTC](https://answers.netlify.com/t/cannot-find-module-bcrypt-error-in-function/101808/1 "2023-09-13T16:29:11Z")

</div>

Hey,

I have this site: [https://elegant-madeleine-866344.netlify.app/](https://elegant-madeleine-866344.netlify.app/)  
I have created a function which imports “bcrypt” module.  
When testing locally with “netlify functions:serve” my function works ok.  
But the deployed function doesn’t work, giving an error: “Cannot find module ‘bcrypt’”

Here are the logs from the Function in Netlify:

```auto
Sep 13, 07:24:02 PM: INIT_START Runtime Version: nodejs:18.v12	Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:0bdff101a7b4e0589af824f244deb93200e4663c2a8d7d0148b76cd00c48777aSep 13, 07:24:02 PM: 2023-09-13T16:24:02.653Z	undefined	ERROR	Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'bcrypt'\nRequire stack:\n- /var/task/netlify/functions/auth.js\n- /var/task/auth.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'bcrypt'","Require stack:","- /var/task/netlify/functions/auth.js","- /var/task/auth.js","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1061:17)"," at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1093:21)"," at async start (file:///var/runtime/index.mjs:1256:23)"," at async file:///var/runtime/index.mjs:1262:1"]}Sep 13, 07:24:02 PM: 2023-09-13T16:24:02.867Z	undefined	ERROR	Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'bcrypt'\nRequire stack:\n- /var/task/netlify/functions/auth.js\n- /var/task/auth.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'bcrypt'","Require stack:","- /var/task/netlify/functions/auth.js","- /var/task/auth.js","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1061:17)"," at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1093:21)"," at async start (file:///var/runtime/index.mjs:1256:23)"," at async file:///var/runtime/index.mjs:1262:1"]}Sep 13, 07:24:02 PM: Unknown application error occurred
Runtime.ImportModuleError

```

Here is my bcrypt version:

```auto
"bcrypt": "^5.1.1",

```

And here is the Network error logged in my Browser

 ![image](https://global.discourse-cdn.com/netlify/original/3X/c/5/c552b6748c26237058cded000f005fb6947c0391.png)

I have tried also to remove “bcrypt” and import another module, (“moment”), to see whether this is a generic issue for every module. But “moment” module worked ok.

Any ideas how to fix this?

Best,  
Panos

---

<div class="post-metadata">

**Author:** ![clarnx](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/clarnx/32/40777_2.png) [@clarnx](https://answers.netlify.com/u/clarnx)\
**Post date:** [September 14, 2023, 6:06am UTC](https://answers.netlify.com/t/cannot-find-module-bcrypt-error-in-function/101808/2 "2023-09-14T06:06:14Z")

</div>

Hi @rapanaki thanks for the post.  
Since Netlify functions run in a serverless environment, trying to install [bcrypt](https://www.npmjs.com/package/bcrypt) has to also install the native dependency [node-gyp](https://github.com/nodejs/node-gyp) which might not install in a serverless environment.

An alternative will be to install and use [bcryptjs](https://www.npmjs.com/package/bcryptjs)  
The `bcryptjs` package is an optimized bcrypt in JavaScript with zero dependencies

Make sure you remove the `bcrypt` package first and then install the `bcryptjs` package

```auto
npm uninstall bcrypt

npm install bcryptjs

```

Kindly make the changes and then let me know the outcome.

Thanks.

---

<div class="post-metadata">

**Author:** ![rapanaki](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/rapanaki/32/54468_2.png) [@rapanaki](https://answers.netlify.com/u/rapanaki)\
**Post date:** [September 15, 2023, 7:28am UTC](https://answers.netlify.com/t/cannot-find-module-bcrypt-error-in-function/101808/3 "2023-09-15T07:28:24Z")

</div>

Hi @clarnx ,

It worked with `bcryptjs`

Thank you!

---

<div class="post-metadata">

**Author:** ![SamO](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/samo/32/41847_2.png) [@SamO](https://answers.netlify.com/u/SamO)\
**Post date:** [September 15, 2023, 6:54pm UTC](https://answers.netlify.com/t/cannot-find-module-bcrypt-error-in-function/101808/4 "2023-09-15T18:54:42Z")

</div>

thanks for confirming you found your solution!
