bcrypt crashing node_modules
Asked Answered
S

3

10

I'm currently building a react native app using typescript and when after running npm i bcrypt node_modules crash and says the error below:

ERROR in ./node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html 1:0 Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders <!doctype html> | <html> | <head>

I tried removing bcrypt and installing it back, but still getting that issue. I also tried remove bcrypt from package.json, removed node_modules and then re-installed node, and works, but when install bcrypt back, it gives the same error.

Any idea?

Straka answered 6/7, 2022 at 3:57 Comment(3)
Are you using ARM as your processor by any chance? Have you tried to do: npm --build-from-source install node-pre-gyp?Monstrosity
gyp is a tool used by Node.js to compile modules written in C/C++. It is just a tool to aid compilation. Node does not ship with a C/C++ compiler by default. Do you have a C compiler and Python installed in your system? (weirdly gyp is written in Python)Parapet
Thanks for asking. I don’t have on this project. I’m installing stuff locally.Straka
S
16

After hours breaking my head on it, I tried using npm i --save-dev @types/bcryptjs instead and then worked.

The import can be used like this: import bcrypt from 'bcryptjs'

Straka answered 6/7, 2022 at 22:56 Comment(2)
I faced the same issue, I did the following to resolve it (my app is TypeScript + NextJs v14) 1- npm i --save-dev bcryptjs 2- npm i --save-dev @types/bcryptjs Thank youHarleyharli
I did the same installed the js version for bcrypt and @types/bcryptjs, the error went away. I'm using TypeScript, not sure why it works. Appreciated if someone who is more knowledgeable could explain this to us.Maw
S
5

I faced a similar issue and successfully resolved it with the following steps:

If you have the existing bcrypt package installed, remove it:

npm rm bcrypt

Install bcryptjs as a development dependency:

npm i --save-dev bcryptjs

Additionally, install the type definitions for bcryptjs:

npm i --save-dev @types/bcryptjs

Following these steps resolved the issue for me.

Hopefully, it helps you too!

Sericeous answered 11/3 at 11:33 Comment(2)
Thanks! This helped. I was stuck on it for hours.Carrycarryall
Why would you install a package which isn't maintained for 7 years?Plasmosome
W
3

I faced the same issue with my node_modules. Alternatively this can be used with react projects: npm i bcryptjs-react link to npm documentation.

Wiskind answered 7/5, 2023 at 7:7 Comment(1)
It worked as intended, thank you!Tunnel

© 2022 - 2024 — McMap. All rights reserved.