Open KingAmo opened 1 year ago
降为3.2.1;在首行加上global.window = this试试
这种线上打包 还要手动更改node_modules 包, 太不友好了
import JSEncrypt from 'jsencrypt/lib/index.js'
const crypt = new JSEncrypt.default()
在node中使用可以这样用
降为3.2.1;在首行加上global.window = this试试
加 global.window = this 可用
今天也遇到了这个问题mock模拟数据时使用了jsencrypt加密出现的版本3.3.2 引入方式:
import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
let decrypt = new JSEncrypt()
解决方式:在jsencrypt.min.js文件中添加如下代码
const window=this
Because import jsencrypt
before global.window
not create,it will result load to failed global.window
,so you should use js the single-threaded,let global.window
is created before to import jsencrypt
, try
(async () => {
global.window = this;
const JSEncrypt = await import('jsencrypt');
const jsencrypt = new JSEncrypt.default();
jsencrypt.setPublicKey(publicKey); // u public key
console.log(`token:\r\n${jsencrypt.encrypt(RSA_VALUE)}`);
})();
v16.19.1
3.3.2