Im writting a web with Angular 6. I need to hash a string client-side, so i'm using createHash("sha256") from 'crypto'.
actually, I just wrote createHash and vscode suggest me the import, which looks like this:
import { createHash } from "crypto";
(this way of importing seems to be fine, and it's used in some typescript tutorial, here) and then:
var hashed = createHash("sha256").update(data).digest()
all syntax is being suggested by vscode, with docstrings and everything. But at the moment of compile with npm start
I get:
ERROR in src/domain/User.ts(2,28): error TS2307: Cannot find module 'crypto'.
as far as I could understand, crypto
is now built-in into node, and I shouldn't have any problem importing it.
also notice that if I run node
in terminal to open a REPL, entering 'crypto' gives me an output that suggest that everything works well.
Here are the versions of everything I think that cares:
node --version: v10.15.1
ng --version:
Angular CLI: 6.2.9
Node: 10.15.1
OS: linux x64
Angular: 6.1.10
typescript 2.9.2
webpack 4.16.4
Any help will be appreciated.
For Typescript 2.* and Angular 2+ -
Install and add this package to the devDependencies.
npm install @types/node --save-dev
In tsconfig.app.json under the compilerOptions, add this -
"types": [ "node" ],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With