Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在react项目里,node版本为18.17,封装了一个加密的ts文件,但是使用的时候页面报错window is not defined #314

Open
SXGaoXiaoYan opened this issue Sep 5, 2024 · 0 comments

Comments

@SXGaoXiaoYan
Copy link

ts文件
import { JSEncrypt } from 'jsencrypt'
// 加密
export function encrypt(this: any, publicKey:string,txt:string) {
const encryptor = new JSEncrypt()
encryptor.setPublicKey(publicKey) // 设置公钥
return encryptor.encrypt(txt) // 对数据进行加密

}

报错信息为
index.js:575 Uncaught ReferenceError: window is not defined
at Object. (file:///Users/gaoxiaoyan/work/smartGpt/Insight-knowledge/client/node_modules/.pnpm/[email protected]/node_modules/jsencrypt/bin/jsencrypt.js:18:4)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:110:18)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant