如何在Angular2中使用'crypto'模块? [英] How to use 'crypto' module in Angular2?

查看:396
本文介绍了如何在Angular2中使用'crypto'模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装模块:

npm install --save crypto

我将其导入到我的组件中

I import it to my component:

import { createHmac } from "crypto";

但是我得到了错误:

--------------(4,28)中的错误:不能 找不到模块"crypto".

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

我在做什么错了?

推荐答案

要将crypto NodeJS库与Typescript一起使用(例如Angular> = 2),请按照以下步骤操作:

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

  1. npm install @types/node --save-dev安装NodeJS定义
  2. tsconfig.ts文件中添加以下内容:

  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" ]

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

使用import * as crypto from 'crypto';

这篇关于如何在Angular2中使用'crypto'模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆