简体   繁体   English

找不到模块“crypto-js”或其相应的类型声明

[英]Cannot find module 'crypto-js' or its corresponding type declarations

I have a project and this project is displaying "QR code" and then for some reason I have to use a certain encoder function and for that I used this library:我有一个项目,这个项目正在显示“二维码”,然后出于某种原因我必须使用某个编码器 function,为此我使用了这个库:

Crypto

i am trying to use Crypto, but i get this error:我正在尝试使用 Crypto,但出现此错误:

Cannot find module 'crypto-js' or its corresponding type declarations.

file.tsx:文件.tsx:

import CryptoJS from 'crypto-js';

const ENC_KEY =
    '50b3cc356d8f34017b3cce1a021389458b898ae85a816201695d11cb87fa1769';
const IV = '07ed0f192b6d8f36c24bd802e0a52cd4';


/**
 * 
 * @param encryptedQR it should be a hex based string
 * @returns a utf8 based decrypted string
 */
export function decrypt(encryptedQR: string) {
    const key = CryptoJS.enc.Hex.parse(ENC_KEY);
    const iv = CryptoJS.enc.Hex.parse(IV);
    const encryptedHex = CryptoJS.enc.Hex.parse(encryptedQR);
    const encrypted = CryptoJS.enc.Base64.stringify(encryptedHex);
    const decrypted = CryptoJS.AES.decrypt(encrypted, key, {
        iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.NoPadding,
    });
    return CryptoJS.enc.Utf8.stringify(decrypted).trim();
}

I solve my problem with this steps:我通过以下步骤解决了我的问题:

1- npm install crypto-js --save
2- npm install @types/crypto-js
3- 
      from: import { CryptoJS } from ‘crypto-js’;
      to: import * as CryptoJS from ‘crypto-js’;

Or或者

1- yarn add crypto-js --save
2- yarn add @types/crypto-js
3- 
      from: import { CryptoJS } from ‘crypto-js’;
      to: import * as CryptoJS from ‘crypto-js’;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:找不到模块“...”或其相应的类型声明 - Type error: cannot find module '...' or its corresponding type declarations 找不到模块“@uppy/core”或其相应的类型声明 - Cannot find module '@uppy/core' or its corresponding type declarations 找不到模块“graphql-hooks”或其相应的类型声明 - Cannot find module 'graphql-hooks' or its corresponding type declarations VSCode:找不到模块“antd”或其相应的类型声明 - VSCode: Cannot find module 'antd' or its corresponding type declarations React:找不到模块或其相应的类型 declarations.ts - React: Cannot find module or its corresponding type declarations.ts 找不到模块“./styles.scss”或其对应的类型声明 - Cannot find module './styles.scss' or its corresponding type declarations React Native - 找不到模块 X 或其相应的类型声明 - React Native - Cannot find module X or its corresponding type declarations 找不到模块“react-lazily”或其相应的类型声明 - Cannot find module 'react-lazily' or its corresponding type declarations 找不到模块“反应”或其相应的类型声明 - Cannot find module 'react' or its corresponding type declarations 找不到模块“下一个”或其相应的类型声明 - Cannot find module 'next' or its corresponding type declarations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM