Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Can't resolve 'crypto' in '\node_modules\bcryptjs\dist' #101

Closed
AshleyJBartlett opened this issue Jun 11, 2019 · 17 comments
Closed
Labels

Comments

@AshleyJBartlett
Copy link

Hi,

I am using bcryptjs (latest version of 2.4.3) in my app developed using Ionic framework.

I am getting the following come up:
[ng] WARNING in ./node_modules/bcryptjs/dist/bcrypt.js
[ng] Module not found: Error: Can't resolve 'crypto' in '\node_modules\bcryptjs\dist'

Any help will be much appreciated.

@dcodeIO
Copy link
Owner

dcodeIO commented Jun 11, 2019

Seems that the library assumes a node environment, thus loading the crypto module to obtain secure random numbers, but actually isn't in a node environment.

@AshleyJBartlett
Copy link
Author

@dcodeIO - Thank you for your prompt response. What do you suggest I do to resolve this?

@Peelz
Copy link

Peelz commented Jul 12, 2019

I've get same problem in react-native, because they not included "crypto" package.

@ChrisMakrutzki
Copy link

I get the same error in angular-cli 8.1.0.

@dcodeIO
Copy link
Owner

dcodeIO commented Jul 22, 2019

So, part of the problem here seems to be that the module attempts to require the crypto module first, expecting that it can catch the resulting error if this fails, but some environments do not allow catching the error but instead abort execution. That about correct?

Maybe one way to deal with this is to invert the checks, first attempting WCA and only then attempting to require the crypto module. Whether this works or not depends on the availability of WCA of course, because if it isn't present, the same error will occur again when attempting the alternative. Someone here willing to try this by patching the library locally?

Additionally, a better check could be added to only attempt requiring the crypto module when sufficiently sure that the code is running inside of a node environment, since without that, the fallback logic will never be able to run.

@akammaru
Copy link

akammaru commented Aug 5, 2019

I have tried to use bcryptjs in React native and get the same error.
After playing about with the code for a bit, I haven't been able to get it to work.
What was sugested, to use WCA didn't work. Its either I don't understand the code or does WCA also use crypto?
Since I have not been able to find a bcrypt package for React native expo so far, I hope either someone can point me in the right direction or I can find a way to get this one to work.

edit
so it would seem it is... as usual, an issue with expo not exposing the nodeJs core but having it's own package system and names.

@nickdotht
Copy link

I've been using react-native-bcrypt instead. Works great.

@papakay
Copy link

papakay commented Oct 8, 2019

I'm having this issue in ember js. Any help please?

@zhyale
Copy link

zhyale commented Feb 15, 2020

Edit:
node_modules@angular-devkit\build-angular\src\angular-cli-files\models\webpack-configs\browser.js

set node to new value:

node: { crypto: true, stream: true, fs: 'empty', net: 'empty' }

@kdlogan19
Copy link

kdlogan19 commented Jul 17, 2020

Any update on this? I am getting the same error. I am working with react-native.

@sertal70
Copy link

This happened to me when debugging my angular app with ng serve, I solved it by adding the following to my package.json:

...
  "browser": {
    "crypto": false
  },
...

Credits go to this SO answer

@rdsedmundo
Copy link

@dcodeIO

the problem here seems to be that the module attempts to require the crypto module first, expecting that it can catch the resulting error if this fails, but some environments do not allow catching the error but instead abort execution. That about correct?

Yes, that is exactly what happens.

@Benandry
Copy link

I have equal problem but i have not idea

@rajann44
Copy link

rajann44 commented Apr 2, 2023

How to solve this issue/warning?

@Benandry
Copy link

Benandry commented Apr 3, 2023 via email

@quannq-vvt
Copy link

I've been using react-native-bcrypt instead. Works great.

I thought this is the same repo?

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!

@github-actions github-actions bot added the stale label Feb 22, 2025
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests