Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

node.js - How to use 'crypto' module in Angular2?

I install module:

npm install --save crypto

I import it to my component:

import { createHmac } from "crypto";

But I get error:

ERROR in -------------- (4,28): Canno t find module 'crypto'.

What am I doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To use crypto NodeJS library with Typescript (Angular >= 2 for example) follow these steps:

  1. npm install @types/node --save-dev to install NodeJS definitions
  2. In tsconfig.ts file add the following:

    "files": [ "./node_modules/@types/node/index.d.ts" ]

  3. Import the library where you want to use it with import * as crypto from 'crypto';


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...