Closed Ferm0494 closed 2 years ago
Are you using this package in node rather than in a browser? If so, add the following to your code file:
global.fetch = require("node-fetch");
const WebCrypto = require("node-webcrypto-ossl");
global.window = {}
global.window.crypto = new WebCrypto()
global.window.btoa = require('btoa');
You will need to npm install those packages too of course
After doing the steps I got
uncaughtException
caused exit: TypeError: WebCrypto is not a constructor
Then after doing the following snippet.
import { Crypto } from "node-webcrypto-ossl";
global.window.crypto = new Crypto();
Getting TextEncoder is not defined.
@Ferm0494 you could try using https://www.npmjs.com/package/web-encoding Then set global.TextEncoder and global.TextDecoder like
import { TextEncoder, TextDecoder } from "web-encoding"
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder
@Ferm0494 let me know if that worked or if you have any more problems/questions. This package was designed to be used in a browser but it should work just fine on a node server as well with those polyfills.
Btw I didn't realize people were using this package but I see it's getting ~10 downloads per week. I'll be updating the dependencies to get rid of all those warnings on install.
Using client and it says fetch is not defined.