Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error Cannot find module 'crypto'

I am trying to use node Crypto module in Angular 7 for asymmetric encryption. and used below command to import the Crypto module

import * as crypto from 'crypto';

but still I am getting error that is

`ERROR in src/app/log-in/log-in.component.ts(11,25): error TS2307: Cannot find module 'crypto'.`

Please help me to resolve the error that how to use this library into Angular.

Thanks in Advance.

like image 685
VIVEK Avatar asked Jul 31 '26 12:07

VIVEK


2 Answers

I was trying to import { randomBytes } from "crypto"; then such error occurred, I installed node types npm install @types/node --save-dev and it was resolved.

like image 192
Gwamaka Charles Avatar answered Aug 03 '26 01:08

Gwamaka Charles


Per the author on npm , The crypto package is no longer available as it is now built in to Node.js. I would suggest looking for an alternative. I came across a Github Gist that contains some suggestions: https://gist.github.com/jo/8619441

Make sure whatever you pick is useable in the browser. Some of the options listed there are server-side only.

like image 25
TheHanna Avatar answered Aug 03 '26 01:08

TheHanna