JonahGroendal / acme-easy

An ACME client for the browser that authenticates via DNS-01 challenge and supports LetsEncrypt by default.
https://www.npmjs.com/package/acme-easy
MIT License
2 stars 1 forks source link

Fetch is not defined... #4

Closed Ferm0494 closed 3 years ago

Ferm0494 commented 3 years ago

Using client and it says fetch is not defined.

JonahGroendal commented 3 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

Ferm0494 commented 3 years ago

After doing the steps I got

 uncaughtException
 caused exit: TypeError: WebCrypto is not a constructor
Ferm0494 commented 3 years ago

Then after doing the following snippet. import { Crypto } from "node-webcrypto-ossl"; global.window.crypto = new Crypto();

Getting TextEncoder is not defined.

JonahGroendal commented 3 years ago

@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
JonahGroendal commented 3 years ago

@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.