我试图在React Typescript中使用crypto-js,但出现以下错误
Module not found: Can't resolve 'crypto-js' in '/app/crypto'
这里是我导入crypto-js。例如:
import crypto from 'crypto-js';
export const encrypt = (key: string, evalue: any) => {
const secret_key = crypto.SHA256(key);
return crypto.AES.encrypt(evalue, secret_key).toString();
};
请帮我解决这个问题,我已经尝试了很多次了,但是没有用。
我最好的猜测是Typescript需要软件包的一些类型定义。
尝试运行npm install @types/crypto-js --save-dev
关于tsconfig.json
文件,我相信这是因为您指定了"include": [ "src" ]
,所以这意味着将跳过所有node_modules
。尝试将其删除并改用baseUrl
选项。
构建项目不需要类型(除非您使用strict
标志)。但是正如@Kael所说,安装它们可能很有用。所以你可以指定
"typeRoots": [
"node_modules/@types"
],
在您的配置文件中